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 });
if (!
constresponse:Response
response.
Response.ok: boolean
The ok read-only property of the Response interface contains a Boolean stating whether the response was successful (status in the range 200-299) or not.
function (typeparameter) TingetJson<T>(url:string):Promise<T|undefined>
T; // the body read is covered by the same deadline
} catch (
function (localvar) error: unknown
error) {
if (
functionisTimeoutError(error:unknown):boolean
True if error is a timeout: a TimeoutError from abortAfter, timeout() or AbortSignal.timeout,
also when wrapped: Node core APIs (fs/promises, timers/promises, streams, events.once) reject with an
AbortError whose cause is the signal's reason.
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.
True for every way an aborted operation fails: this library's
AbortError
, and any error
named AbortError or TimeoutError (the DOMExceptions that fetch, AbortSignal.timeout,
abortAfter and throwIfAborted produce).
@example
try {
awaitfetch(url, { signal: controller.signal });
} catch (error) {
if (isAbortError(error)) return; // cancelled or timed out
throw error;
}
isAbortError(
var error:unknown
error)) throw
var error:unknown
error;
} 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.
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.
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.
True for every way an aborted operation fails: this library's
AbortError
, and any error
named AbortError or TimeoutError (the DOMExceptions that fetch, AbortSignal.timeout,
abortAfter and throwIfAborted produce).
@example
try {
awaitfetch(url, { signal: controller.signal });
} catch (error) {
if (isAbortError(error)) return; // cancelled or timed out
throw error;
}
isAbortError(
function (localvar) error: unknown
error)) throw
function (localvar) error: unknown
error;
} 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.
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.
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 AbortSignal interface represents a signal object that allows you to communicate with an asynchronous operation (such as a fetch request) and abort it if required via an AbortController object.
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.
EnhancedAbortController.createLinkedController<EnhancedAbortController>(this: new () => EnhancedAbortController, ...signals: Array<AbortSignal |null|undefined>): EnhancedAbortController
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.
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.
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.
EnhancedAbortController.createLinkedController<EnhancedAbortController>(this: new () => EnhancedAbortController, ...signals: Array<AbortSignal |null|undefined>): EnhancedAbortController
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.
createLinkedController(
usingoverall:EnhancedAbortController
overall.
EnhancedAbortController.signal: EnhancedSignal
The controller's signal: a real AbortSignal, always the same object.
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 });
} catch (
function (localvar) error: unknown
error) {
// Give up on real errors, on the caller's cancel and on the overall budget; retry only a per-attempt timeout.
if (!
functionisTimeoutError(error:unknown):boolean
True if error is a timeout: a TimeoutError from abortAfter, timeout() or AbortSignal.timeout,
also when wrapped: Node core APIs (fs/promises, timers/promises, streams, events.once) reject with an
AbortError whose cause is the signal's reason.
isTimeoutError(
function (localvar) error: unknown
error) ||
usingoverall:EnhancedAbortController
overall.
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).
Here the per-attempt child times out with its own TimeoutError while overall stays live; when overall (or the caller’s signal) aborts, its reason flows into the child and the loop stops.
fetch rejects with the signal’s reason: TimeoutError for deadlines, AbortError for abort(), or your custom reason. Classify with isAbortError / isTimeoutError; see Reasons & errors.