export class FormatQueue { private queue: (() => Promise)[] = []; private processing = false; private readonly delay: number; constructor(delay: number) { this.delay = delay; } enqueue(formatFn: () => Promise) { 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; } }