Skip to content
Buy me a coffee

EnhancedAbortController

Defined in: src/EnhancedAbortController.ts:64

An AbortController with .NET CancellationTokenSource features. It is an AbortController, and controller.signal is a real AbortSignal: pass it to fetch, AbortSignal.any, streams, timers and any other API that takes a signal.

const controller = new EnhancedAbortController().abortAfter(TimeSpan.fromSeconds(5));
const response = await fetch(url, { signal: controller.signal });
  • AbortController
  • Disposable

new EnhancedAbortController(): EnhancedAbortController

Defined in: src/EnhancedAbortController.ts:69

EnhancedAbortController

AbortController.constructor

get isAborted(): boolean

Defined in: src/EnhancedAbortController.ts:91

Same as signal.aborted.

boolean


get isDisposed(): boolean

Defined in: src/EnhancedAbortController.ts:101

True after dispose.

boolean


get reason(): unknown

Defined in: src/EnhancedAbortController.ts:96

Same as signal.reason: why it aborted, undefined until then.

unknown


get signal(): EnhancedSignal

Defined in: src/EnhancedAbortController.ts:86

The controller’s signal: a real AbortSignal, always the same object.

EnhancedSignal

AbortController.signal

[dispose](): void

Defined in: src/EnhancedAbortController.ts:139

void

Disposable.[dispose]


abort(reason?): void

Defined in: site/node_modules/typescript/lib/lib.dom.d.ts:2729

The abort() method of the AbortController interface aborts an asynchronous operation before it has completed.

MDN Reference

any

void

AbortController.abort


abortAfter(delay): this

Defined in: src/EnhancedAbortController.ts:114

Aborts after delay, like .NET’s CancelAfter: calling it again replaces the previous schedule, and Infinity / -1 / TimeSpan.infinite cancel it. The reason is a DOMException named TimeoutError, as with AbortSignal.timeout. The timer never keeps the process alive, and delays longer than 24.8 days work. Does nothing once aborted. Returns the controller, for chaining.

Delay

this

RangeError for NaN, negative (other than -1) or non-numeric delays.

Error if the controller was disposed.


abortAfterTimeSpan(timeSpan): this

Defined in: src/EnhancedAbortController.ts:124

Same as abortAfter with a TimeSpan. Kept for 1.x code.

TimeSpan

this


dispose(): void

Defined in: src/EnhancedAbortController.ts:133

Releases what the controller holds: the scheduled abort and the listeners it put on linked parent signals. It does not abort (like .NET’s Dispose); call abort() first if work should stop. abort() still works afterwards. Safe to call more than once; supports using.

void


static createLinkedController<C>(this, …signals): C

Defined in: src/EnhancedAbortController.ts:160

A controller that aborts as soon as any of signals aborts, with that signal’s reason, like .NET’s CreateLinkedTokenSource. Aborting the linked controller does not affect the parents. Its listeners on the parents are removed when it aborts or is disposed, so short-lived links on a long-lived parent don’t leak. undefined/null entries (optional signals) and EnhancedAbortSignal.none are skipped.

C extends EnhancedAbortController

new () => C

…(AbortSignal | null | undefined)[]

C


static linkSignals<C>(this, …signals): C

Defined in: src/EnhancedAbortController.ts:177

Same as createLinkedController.

C extends EnhancedAbortController

new () => C

…(AbortSignal | null | undefined)[]

C


static timeout<C>(this, delay): C

Defined in: src/EnhancedAbortController.ts:150

A controller that aborts after delay, with a TimeoutError reason.

C extends EnhancedAbortController

new () => C

Delay

C