/** A failure-resilient FIFO for read/derive/write mutations of shared state. */ export class AsyncSerialQueue { #tail: Promise = Promise.resolve(); run(operation: () => Promise): Promise { const result = this.#tail.then(operation, operation); this.#tail = result.then( () => undefined, () => undefined, ); return result; } }