Spaces:
Paused
Paused
File size: 744 Bytes
f55c62a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | export class FormatQueue {
private queue: (() => Promise<void>)[] = [];
private processing = false;
private readonly delay: number;
constructor(delay: number) {
this.delay = delay;
}
enqueue(formatFn: () => Promise<void>) {
this.queue = [formatFn];
this.process();
}
private async process() {
if (this.processing) return;
this.processing = true;
while (this.queue.length > 0) {
const formatFn = this.queue.shift();
if (formatFn) {
try {
await formatFn();
} catch (error) {
console.error('Error in format queue:', error);
}
await new Promise((resolve) => setTimeout(resolve, this.delay));
}
}
this.processing = false;
}
}
|