/** * Runs asynchronous operations in call order while keeping the queue usable * after an individual operation rejects. */ export class SerializedAsyncQueue { private tail: Promise = Promise.resolve(); run(operation: () => Promise): Promise { const result = this.tail.then(operation, operation); this.tail = result.then( () => undefined, () => undefined, ); return result; } }