🧵(react) add Queue util
This util processes function given to it sequentially, using a FIFO strategy.
This commit is contained in:
14
packages/react/src/utils/Queue.ts
Normal file
14
packages/react/src/utils/Queue.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
export class Queue {
|
||||||
|
private lastJob?: Promise<any>;
|
||||||
|
|
||||||
|
push(job: () => Promise<any>): Promise<any> {
|
||||||
|
const work = async () => {
|
||||||
|
if (this.lastJob) {
|
||||||
|
await this.lastJob;
|
||||||
|
}
|
||||||
|
return job();
|
||||||
|
};
|
||||||
|
this.lastJob = work();
|
||||||
|
return this.lastJob;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user