/** Serializes complete read-modify-write jobs for one Session. */ export class MutationLine { private tail: Promise = Promise.resolve(); private sealedError: Error | undefined; run(operation: () => T | Promise): Promise { if (this.sealedError !== undefined) return Promise.reject(this.sealedError); const result = this.tail.then(() => { if (this.sealedError !== undefined) throw this.sealedError; return operation(); }); this.tail = result.then( () => undefined, () => undefined, ); return result; } seal(error: Error): Promise { this.sealedError ??= error; return this.tail; } }