/** * Wraps the subset of `AbortSignal` static methods that `combineAbortSignals` * needs. Serves two real uses: * * 1. Runtime feature detection. `AbortSignal.any()` isn't present on every * platform we support (Node <19, older browsers, some sandboxed * runtimes), so `combineAbortSignals` checks `any` at call time and * falls back to manual listener wiring when it's missing. * 2. Test injection. Tests pass a fake `abortSignalApi` to force a * specific branch (native vs. fallback) regardless of what the current * runtime actually supports. * * By default, `combineAbortSignals` reads the real globals via * `getAbortSignalApi()`; callers rarely need to pass this explicitly. */ export interface AbortSignalApi { any?: (signals: AbortSignal[]) => AbortSignal; } export interface DisposableAbortSignal { signal: AbortSignal; /** * Release the resources backing this signal (timers, event listeners). * Safe to call multiple times. */ dispose: () => void; } /** * True for fetch-abort throws: Node and browsers both raise an `Error` * (or `DOMException`, which is itself an `Error` subclass in modern * runtimes) with `name === "AbortError"` when an in-flight request is * cancelled. Anything else, even racing with `signal.aborted`, is a real * failure (auth, validation, transport) and should reject normally. * * Centralized here so all callers agree on the predicate — divergent * copies were possible (e.g., one site adding a `DOMException` branch * while another stayed strict on `Error`) and a silent mismatch in this * test would mean some abort paths swallow errors that others surface. */ export declare function isAbortError(err: unknown): boolean; export declare function createTimeoutError(timeoutMs: number): Error; /** * Creates an AbortSignal that fires after `timeoutMs` using a cancellable * `AbortController` + `setTimeout`. We intentionally don't delegate to the * native `AbortSignal.timeout()` — its returned signal has no way to cancel * the underlying timer, which would make `dispose()` a lie on that path and * give us divergent abort-reason messages across runtimes. * * On Node-like runtimes we `unref()` the timer so a pending timeout doesn't * keep the process alive. In browsers `.unref` is absent and the guard is a * harmless no-op. * * The signal's abort reason is a `DOMException` with `name: "TimeoutError"` * so callers can distinguish timeout-driven aborts from caller-driven ones. * * Always call `dispose()` when the signal is no longer needed to clear the * pending timer. */ export declare function createTimeoutAbortSignal({ timeoutMs, }: { timeoutMs: number; }): DisposableAbortSignal; /** * Combines multiple disposable abort handles so the result aborts when *any* * source does. Uses native `AbortSignal.any()` when available; otherwise wires * up listeners manually. * * Returns `undefined` when the array is empty, or passes through a single * handle without wrapping it. * * Always call `dispose()` on the result when it is no longer needed. This * removes event listeners from source signals and calls `dispose()` on every * input handle (releasing timers, etc). */ export declare function combineAbortSignals({ handles, abortSignalApi, }: { handles: DisposableAbortSignal[]; abortSignalApi?: AbortSignalApi; }): DisposableAbortSignal | undefined; //# sourceMappingURL=abort-utils.d.ts.map