AbortSignal: abort() static method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2021.
Note: This feature is available inWeb Workers.
TheAbortSignal.abort() static method returns anAbortSignal that is already set as aborted (and which does not trigger anabort event).
This is shorthand for the following code:
const controller = new AbortController();controller.abort();return controller.signal;This could, for example, be passed to a fetch method in order to run its abort logic (i.e., it may be that code is organized such that the abort logic should be run even if the intended fetch operation has not been started).
Note:The method is similar in purpose toPromise.reject.
In this article
Syntax
AbortSignal.abort()AbortSignal.abort(reason)Parameters
reasonThe reason why the operation was aborted, which can be any JavaScript value.If not specified, the reason is set to "AbortError"
DOMException.
Return value
AnAbortSignal instance with theAbortSignal.aborted property set totrue, andAbortSignal.reason set to the specified or default reason value.
Specifications
| Specification |
|---|
| DOM> # ref-for-dom-abortsignal-abort①> |