Files
cunningham/packages/react/src/utils/Queue.ts

15 lines
282 B
TypeScript
Raw Normal View History

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