global.AbortController
Makes a signal and cancels whatever it was given to, a fetch or a task, with an optional reason.
Usage
Fetch JSON and handle failure
const token = 'my-token';
const { signal } = new AbortController();
const response = await fetch('https://example.com/logo.png', {
headers: { Authorization: `Bearer ${token}` },
signal,
});
response.status; // 200
const bytes = await response.arrayBuffer();Constructors
(): AbortControllerParameters
No parameters.
Returns
AbortController
Properties and methods 3
| Name | Type | Required | Description |
|---|---|---|---|
prototypereadonly | AbortController | Yes | — |
signalreadonly | AbortSignal | Yes | — |
abort | (reason?: unknown) => void | Yes | — |
abort — method signatures
Signatures
(reason?: unknown): voidParameters
| Name | Type | Required | Description |
|---|---|---|---|
reason | unknown | No | — |
Returns
void
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.