/** * Abort utilities (#110) - the shared vocabulary for cancellation. * * Handlers that observe an AbortSignal THROW an abort-shaped error (never * return an isError response); callers classify with isAbortError. linkSignals * is hand-rolled instead of AbortSignal.any because (a) `engines` allows Node * >=18.0.0 and AbortSignal.any needs 18.17/20.3, and (b) AbortSignal.any can * never detach its listeners - this code links against a long-lived run * signal once per step, so dispose() in a `finally` is mandatory to keep a * 500-step run from accumulating hundreds of dead listeners. */ /** Error thrown when an operation is cancelled via an AbortSignal. */ export declare class AbortError extends Error { readonly reason?: unknown | undefined; readonly code = "ABORTED"; constructor(message?: string, reason?: unknown | undefined); } /** * Whether an error means "cancelled" rather than "failed". * * Matches by name, not instanceof, because aborts arrive in several shapes: * our own AbortError class, the DOMException fetch throws (NOT instanceof * Error in every runtime), and whatever `signal.throwIfAborted()` rethrows * (the signal's reason - a DOMException by default, anything the aborter * passed otherwise). Getting this wrong turns a user's cancel into a * "genuine failure" with diagnostics gathered against a browser they just * tore down. */ export declare function isAbortError(err: unknown): boolean; /** The abort-shaped error to raise for `signal`: its reason when the reason * is itself abort-shaped, a fresh AbortError wrapping it otherwise. */ export declare function abortErrorFor(signal: AbortSignal): Error; /** Throw the abort-shaped error for `signal` if it has already aborted. */ export declare function throwIfAborted(signal?: AbortSignal): void; export interface LinkedSignal { signal: AbortSignal; /** Detach every listener this link attached to its input signals. MUST be * called (in a `finally`) once the linked operation settles - the inputs * may be long-lived run signals that outlive the operation by minutes. */ dispose(): void; } /** * Combine signals: the returned signal aborts as soon as ANY input does * (immediately, if one already has), carrying that input's reason. * Undefined inputs are skipped so optional signals compose without ceremony. */ export declare function linkSignals(...signals: Array): LinkedSignal; /** * Sleep that REJECTS (with an abort-shaped error) when `signal` aborts. * Listener and timer are cleaned up on every path. */ export declare function abortableSleep(ms: number, signal?: AbortSignal): Promise; /** * Await `promise` unless `signal` aborts first, in which case REJECT with an * abort-shaped error and stop waiting. The underlying work is NOT cancelled - * this is "stop waiting", for operations with no cancellation API (a page * navigation already handed to the browser). On abort the orphaned promise * gets a no-op catch so its eventual rejection never surfaces as unhandled. * The listener is detached on every path. */ export declare function raceAbort(promise: Promise, signal?: AbortSignal): Promise; /** * Non-throwing sleep variant preserving the replay executor's shape: resolves * `true` if the signal aborted before the delay elapsed, `false` otherwise. * Unlike the bespoke helper it replaces, cleanup leaves no extra timer alive. */ export declare function abortableDelayResult(ms: number, signal?: AbortSignal): Promise; //# sourceMappingURL=abort.d.ts.map