-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed(#1355): Task Status randomly not saving updated value
- Loading branch information
1 parent
18fad04
commit 48a2ee4
Showing
5 changed files
with
71 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './clsxm'; | ||
export * from './is-valid-url'; | ||
export * from './scroll-to-element'; | ||
export * from './queue'; | ||
export * from './wait'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { wait } from './wait'; | ||
|
||
export class Queue { | ||
private running = false; | ||
private queues: (() => void)[] = []; | ||
|
||
constructor(private poolSize = 1) {} | ||
|
||
private _task(func: (...params: any) => void, ...params: any[]) { | ||
return () => func(...params); | ||
} | ||
|
||
public task<F extends any[], T extends (...params: F) => void>( | ||
func: T, | ||
...params: F | ||
) { | ||
this.queues.push(this._task(func, ...params)); | ||
|
||
if (this.running === false) { | ||
this.running = true; | ||
wait(0.1).then(() => this.work()); | ||
} | ||
} | ||
|
||
private async work() { | ||
const tasks = this.queues.splice(0, this.poolSize); | ||
if (tasks.length === 0) { | ||
this.running = false; | ||
return; | ||
} | ||
|
||
await Promise.allSettled(tasks.map((fn) => fn())); | ||
this.work(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function wait(sec = 1) { | ||
return new Promise((resolve) => setTimeout(resolve, sec * 1000)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters