1/**
2 * Runs asynchronous operations in call order while keeping the queue usable
3 * after an individual operation rejects.
4 */
5export class SerializedAsyncQueue {
6 private tail: Promise<void> = Promise.resolve();
7
8 run<T>(operation: () => Promise<T>): Promise<T> {
9 const result = this.tail.then(operation, operation);
10 this.tail = result.then(
11 () => undefined,
12 () => undefined,
13 );
14 return result;
15 }
16}