export type AsyncQueue = { enqueue(operation: () => Promise): Promise; }; export function createAsyncQueue(): AsyncQueue { let tail = Promise.resolve(); return { enqueue(operation: () => Promise): Promise { const run = tail.then(operation, operation); tail = run.then( () => undefined, () => undefined, ); return run; }, }; }