/** * One externally completed promise used only inside the live kernel. * * Durable waits use workflow instructions. This helper is for in-process * ownership such as reducer tests, Step adapters, and protocol correlation. */ export class Deferred { readonly promise: Promise; #resolve!: (value: Value | PromiseLike) => void; #reject!: (reason?: unknown) => void; #settled = false; constructor() { this.promise = new Promise((resolve, reject) => { this.#resolve = resolve; this.#reject = reject; }); } /** Resolve once. Later completion attempts are ignored. */ resolve(value: Value | PromiseLike): void { if (this.#settled) return; this.#settled = true; this.#resolve(value); } /** Reject once. Later completion attempts are ignored. */ reject(reason?: unknown): void { if (this.#settled) return; this.#settled = true; this.#reject(reason); } }