Files
cunningham/packages/react/src/utils/Queue.ts
Nathan Vasse dd1a677a76 🧵(react) add Queue util
This util processes function given to it sequentially, using a FIFO
strategy.
2024-01-05 16:38:09 +01:00

15 lines
282 B
TypeScript

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;
}
}