Skip to content

Function: combineAbortSignals()

combineAbortSignals(…signals): AbortSignal | undefined

Combine several optional cancellation sources into one signal that aborts as soon as any of them does.

The usual caller is an operation that has to honor more than one source at once - a caller’s own signal (a closed connection, an agent run being cancelled) plus one derived from a timeout - where the awaited I/O accepts only a single signal. Absent sources are ignored, and a lone signal is returned as-is so the common path allocates nothing. Returns undefined only when every input is absent, which callers can pass straight through to an optional signal parameter.

Aborting an input aborts the result (carrying that input’s reason); nothing propagates back the other way.

…(AbortSignal | undefined)[]

AbortSignal | undefined

await fetch(url, { signal: combineAbortSignals(req.signal, timeout.signal) });