AbortController
AbortController represents the side that issues a cancellation. Its signal is handed to fetch() or Request, and calling abort() cancels those requests.
One signal can be handed to several requests, and a single abort() cancels them all. Requests that have already completed are unaffected. Cancellation cannot be undone; to send requests again, create a new AbortController.
Inheritance: AbortController does not inherit from any other class.
For how to cancel requests and set timeouts on them, see the guide Fetching data from the network.
Constructor
Creates a controller and its signal.
Instance properties
| Property | Description |
|---|---|
signal read-only | The corresponding AbortSignal |
Instance methods
| Method | Description |
|---|---|
abort() | Cancels |
Examples
js
const controller = new AbortController();
controller.signal.addEventListener('abort', () => {
console.log('Aborted');
});
controller.abort();Result: Prints Aborted.
Differences from the web
The same as on the web.
See also
AbortSignal: the cancellation state and reasonfetch()