It does not abort. Like .NET’s CancellationTokenSource.Dispose, it is about resources, not about stopping work. Code waiting on the signal is not woken up.
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.
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.
@throws ― RangeError for NaN, negative (other than -1) or non-numeric delays.
@throws ― Error if the controller was disposed.
abortAfter(100);
constcontroller:EnhancedAbortController
controller.
EnhancedAbortController.dispose(): void
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.
dispose();
constcontroller:EnhancedAbortController
controller.
EnhancedAbortController.signal: EnhancedSignal
The controller's signal: a real AbortSignal, always the same object.
signal.
AbortSignal.aborted: boolean
The aborted read-only property returns a value that indicates whether the asynchronous operations the signal is communicating with are aborted (true) or not (false).
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.
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.
@throws ― RangeError for NaN, negative (other than -1) or non-numeric delays.
@throws ― Error if the controller was disposed.
abortAfter(
classTimeSpan
An immutable time interval, stored in milliseconds. Modeled on .NET's TimeSpan.
The controller's signal: a real AbortSignal, always the same object.
signal);
} // finished in 1 s? The 5 s timer is cleared here.
Keep the await in return await: without it the function returns the pending promise, using disposes at once, and the deadline is gone while the work still runs.
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.
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.
@throws ― RangeError for NaN, negative (other than -1) or non-numeric delays.
@throws ― Error if the controller was disposed.
abortAfter(5000);
try {
await
functionwork(signal:AbortSignal):Promise<string>
work(
constcontroller:EnhancedAbortController
controller.
EnhancedAbortController.signal: EnhancedSignal
The controller's signal: a real AbortSignal, always the same object.
signal);
} finally {
constcontroller:EnhancedAbortController
controller.
EnhancedAbortController.dispose(): void
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.