npm install --save extra-abort
# or
yarn add extra-abortThe WHATWG AbortController and AbortSignal.
class AbortError extends CustomError {}It is not the real AbortError,
but you can do err instance AbortError like it is,
because it can recognizes other errors that match the pattern of AbortError.
class TimeoutError extends AbortError {}It is not the real TimeoutError,
but you can do err instance TimeoutError like it is,
because it can recognizes other errors that match the pattern of TimeoutError.
class LinkedAbortController extends AbortController {
constructor(signal: AbortSignal)
}It is a special AbortController that takes an AbortSignal as a parameter.
It will abort itself when its parameter signal aborts,
you can make it abort by calling its abort method too.
function timeoutSignal(ms: number): AbortSignalIt will abort after ms milliseconds.
await fetch('http://example.com', { signal: timeoutSignal(5000) })/**
* @throws {AbortError}
*/
function withAbortSignal<T>(signal: AbortSignal | Falsy, fn: () => PromiseLike<T>): Promise<T>If AbortSignal is aborted, the promise will be rejected with AbortError.
function raceAbortSignals(signals: Array<AbortSignal | Falsy>): AbortSignalThe Promise.race function for AbortSignal.
function isAbortSignal(val: unknown): val is AbortSignalfunction lastCallOnly<T, Args extends unknown[]>(
fn: (...args: [...args: Args, signal: AbortSignal]) => PromiseLike<T>
): (...args: [...args: Args, signal: AbortSignal | Falsy]) => Promise<T>