🧵(react) add Queue util

This util processes function given to it sequentially, using a FIFO
strategy.
This commit is contained in:
Nathan Vasse
2024-01-05 11:53:49 +01:00
committed by NathanVss
parent 68608b5390
commit dd1a677a76

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