Files
t3code/apps/mobile/src/lib/serialized-async-queue.ts
T
2026-07-16 14:29:17 +00:00

17 lines
431 B
TypeScript

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