Skip to content

getSharedAbortSignal

The signal of the app-wide shared ResettableAbortController.

Call it at the start of each operation. Never cache it, or the operation after the first abort starts already aborted.

Import:

import { getSharedAbortSignal } from '@mnaoumov/typescript-lib/abort-controller';

Example:

const abortSignal = getSharedAbortSignal();
for (const url of urls) {
abortSignal.throwIfAborted();
await fetch(url, { signal: abortSignal });
}

Signature:

function getSharedAbortSignal(): AbortSignal

Returns: AbortSignal — The AbortSignal of the shared ResettableAbortController.

Example:

const abortSignal = getSharedAbortSignal();
for (const url of urls) {
abortSignal.throwIfAborted();
await fetch(url, { signal: abortSignal });
}

Links to this page: