Install
npm install --save extra-abort
yarn add extra-abort
API
AbortController, AbortSignal
Ponyfills of WHATWG AbortController and AbortSignal.
AbortError
class AbortError extends CustomError {}
It is not the real AbortError
of fetch
,
but you can do err instance AbortError
like it is,
because it can recognizes other errors that match the pattern of AbortError
.
timeoutSignal
function timeoutSignal(ms: number): AbortSignal
It will abort after ms
milliseconds.
await fetch('http://example.com', { signal: timeoutSignal(5000) })
withAbortSignal
function withAbortSignal<T>(signal: AbortSignal, fn: () => PromiseLike<T>): Promise<T>
If AbortSignal
is aborted, the promise will be rejected with AbortError
.
raceAbortSignals
function raceAbortSignals(abortSignals: Array<AbortSignal | Falsy>): AbortSignal
The Promise.race
function for AbortSignal
.