export interface QueuedOperation { label: string; run: () => Promise; } export class OperationQueue { private tail: Promise = Promise.resolve(); private activeLabel: string | undefined; enqueue(operation: QueuedOperation): Promise { const runAfterTail = this.tail.catch(() => undefined).then(async () => { this.activeLabel = operation.label; try { return await operation.run(); } finally { this.activeLabel = undefined; } }); this.tail = runAfterTail; return runAfterTail; } currentOperation(): string | undefined { return this.activeLabel; } }