Skip to content
Source
Sign inSign up
Open History to see the last commit

serialized-async-queue.ts

12 lines304 Bytes

1export class SerializedAsyncQueue {
2 private tail: Promise<void> = Promise.resolve();
3​
4 run<T>(operation: () => Promise<T>): Promise<T> {
5 const result = this.tail.then(operation, operation);
6 this.tail = result.then(
7 () => undefined,
8 () => undefined,
9 );
10 return result;
11 }