Vize

abort-signal

Create a signal that aborts when the first input signal aborts.

Package @vizejs/composable/abort-signal
Own the source vize lib pull composable:abort-signal
Runtime exports anyAbortSignal, timeoutAbortSignal, deadlineAbortSignal
Gzip budget 3072 B

Usage

import { anyAbortSignal, timeoutAbortSignal, deadlineAbortSignal } from "@vizejs/composable/abort-signal";

Runtime contract

Utility Category Stability SSR Hydration Cleanup Targets Host globals Uses
anyAbortSignal async experimental safe not-applicable returned-value web, server, worker, native, desktop, terminal AbortController, AbortSignal —
timeoutAbortSignal timing experimental safe not-applicable returned-value web, server, worker, native, desktop, terminal AbortController, AbortSignal, DOMException, globalThis anyAbortSignal
deadlineAbortSignal timing experimental safe not-applicable returned-value web, server, worker, native, desktop, terminal — timeoutAbortSignal

API

anyAbortSignal

Create a signal that aborts when the first input signal aborts. The standard AbortSignal.any() implementation is used when available. Older runtimes receive an equivalent listener-based implementation that removes every retained listener as soon as the result aborts. The first already-aborted input wins in iteration order, and its exact reason is forwarded. An empty iterable returns a fresh signal that never aborts. This function reads runtime constructors only when called and is safe to import during server rendering. Materializing the iterable happens before listeners are attached, so an iterable that throws cannot leak a partial subscription. If a non-standard signal throws while registering, listeners already attached to earlier inputs are released before the error propagates.

function anyAbortSignal(signals: Iterable<AbortSignal>): AbortSignal

timeoutAbortSignal

Create a signal that aborts after a portable, non-negative delay. The native AbortSignal.timeout() implementation is used when available and neither a custom scheduler nor a custom reason is supplied. Older runtimes use the same owned-timer path as injected schedulers. Parent cancellation is composed with first-reason-wins semantics. Compatibility scheduling owns exactly one timer and removes its parent listener whenever either source aborts. A zero delay remains asynchronous. The delay must be an integer from 0 through 2_147_483_647; this common signed 32-bit timer ceiling avoids host-specific clamping. The function accesses timers and abort constructors only when called and is safe to import during server rendering.

function timeoutAbortSignal( delayMs: number, options: TimeoutAbortSignalOptions = {}, ): AbortSignal

deadlineAbortSignal

Create a timeout signal from an absolute Unix-epoch deadline. Fractional positive differences are rounded up so cancellation never occurs before the requested deadline. Past deadlines become an asynchronous zero-delay timeout. Date and numeric deadlines are both accepted.

function deadlineAbortSignal( deadline: Date | number, options: DeadlineAbortSignalOptions = {}, ): AbortSignal

Types

TimeoutAbortSignalOptions

Options for timeoutAbortSignal.

Member Type Description
signal? AbortSignal Abort the returned signal early when this parent aborts.
reason? unknown Reason used when the timeout elapses. Parent cancellation always forwards the parent's reason instead.
scheduler? TimeoutScheduler Deterministic or host-specific single-shot timer implementation. Supplying a scheduler selects the compatibility implementation.

DeadlineAbortSignalOptions

Options for deadlineAbortSignal.

Member Type Description
signal? AbortSignal Abort the returned signal early when this parent aborts.
reason? unknown Reason used when the timeout elapses. Parent cancellation always forwards the parent's reason instead.
scheduler? TimeoutScheduler Deterministic or host-specific single-shot timer implementation. Supplying a scheduler selects the compatibility implementation.
now? () => number Clock returning Unix epoch milliseconds.