dom / latest / abortsignal / abort.html /

AbortSignal.abort()

The static AbortSignal.abort() method returns an AbortSignal that is already set as aborted (and which does not trigger an abort 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 to Promise.reject.

Syntax

abort()
abort(reason)

Parameters

reason

The reason why the operation was aborted, which can be any JavaScript value. If not specified, the reason is set to "AbortError" DOMException.

Return value

An AbortSignal instance with the AbortSignal.aborted property set to true, and AbortSignal.reason set to the specified or default reason value.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
abort
93
93
88
No
79
15
93
93
88
66
15
17.0
reason_parameter
No
No
97
No
No
No
No
No
97
No
No
No

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/abort