Cheat sheet
import { EnhancedAbortController, EnhancedAbortSignal, TimeSpan, register, whenAborted, AbortRegistration, AbortError, isAbortError, isTimeoutError, type Delay, type EnhancedSignal,} from '@ylcnfrht/enhanced-abort-controller';EnhancedAbortController (extends AbortController)
Section titled “EnhancedAbortController (extends AbortController)”| Member | Behaviour |
|---|---|
new EnhancedAbortController() |
A real AbortController |
.signal |
Native AbortSignal (EnhancedSignal), same object every time |
.signal.register(cb) · .signal.whenAborted · .signal.canBeAborted |
Extras on the controller’s own signal; whenAborted is cached |
.abort(reason?) |
Native; works after dispose() |
.abortAfter(delay) |
Replaces any schedule; Infinity / -1 / TimeSpan.infinite cancel; TimeoutError reason; RangeError on bad delays; throws if disposed; no-op once aborted; returns this; unref’d timer |
.abortAfterTimeSpan(span) |
1.x name for abortAfter(span) |
.dispose() · using |
Releases timer and parent links; does not abort; idempotent |
.isAborted · .reason · .isDisposed |
State |
EnhancedAbortController.timeout(delay) |
new EnhancedAbortController().abortAfter(delay) |
EnhancedAbortController.createLinkedController(...signals) · linkSignals |
Aborts with the first parent’s reason; skips undefined / null / none; removes parent listeners on abort or dispose |
Any AbortSignal
Section titled “Any AbortSignal”| Function | Behaviour |
|---|---|
register(signal, cb) |
cb(reason) once on abort; runs now if already aborted (its error propagates); returns AbortRegistration; errors in later callbacks are uncaught in Node |
whenAborted(signal) |
Promise of the reason; never rejects |
isAbortError(e) |
Library AbortError or any error named AbortError / TimeoutError |
isTimeoutError(e) |
Error named TimeoutError, or one whose cause is (Node core APIs wrap it) |
AbortRegistration
Section titled “AbortRegistration”unregister() · dispose() · using · isDisposed (true after unregister, after the callback ran, or if registered on an aborted signal).
EnhancedAbortSignal (helper object)
Section titled “EnhancedAbortSignal (helper object)”| Helper | |
|---|---|
none |
One signal that never aborts; registers no listeners |
aborted |
Getter: a new aborted signal |
timeout(delay) |
AbortSignal.timeout + TimeSpan; Infinity → none; > 24.8 days chained |
any(signals) |
Native AbortSignal.any, skipping undefined / null / none; nothing left → none |
register · whenAborted |
The standalone functions |
canBeAborted(signal) |
false only for none |
TimeSpan
Section titled “TimeSpan”fromMilliseconds/Seconds/Minutes/Hours/Days · milliseconds · totalSeconds/Minutes/Hours/Days · add · subtract · equals · compareTo · valueOf · toString() → "1500ms" · zero · infinite (-1) · maxValue · minValue. Non-finite input throws RangeError.
AbortError
Section titled “AbortError”new AbortError(message = 'The operation was aborted.', { cause }), name === 'AbortError'.
Gotchas
Section titled “Gotchas”- Pass
controller.signal, nevercontroller.signal.signal(1.x). using+return promisedisposes too early:return await.- A pending
abortAfteralone doesn’t keep Node alive (top-level await exits with code 13). - A custom
abort(new Error(...))reason is not an abort error: checksignal.abortedin thecatch.