AbortSignal
Represents a signal object that allows you to communicate with an asynchronous operation and abort it if desired
Syntax
AbortSignal.abort(reason?) / AbortSignal.timeout(ms)Parameters
| Parameter | Type | Description |
|---|---|---|
| reason | any | The abort reason |
| ms | number | Milliseconds until auto-abort for timeout() |
Return Value
An AbortSignal instance
Examples
const signal = AbortSignal.abort('cancelled')
console.log(signal.aborted) // true
console.log(signal.reason) // 'cancelled'const signal = AbortSignal.timeout(5000)
fetch('/api/data', { signal })
.then(res => res.json())
.catch(err => console.log('Timed out or aborted'))const signals = [AbortSignal.timeout(3000)]
const combined = AbortSignal.any(signals)
fetch('/api/slow', { signal: combined })
.catch(() => console.log('Aborted'))Understanding AbortSignal
The AbortSignal method in JavaScript represents a signal object that allows you to communicate with an asynchronous operation and abort it if desired. It belongs to the AbortController object and is one of the most widely used methods for working with abortcontroller values in modern JavaScript and TypeScript applications.
The method signature is AbortSignal.abort(reason?) / AbortSignal.timeout(ms). It accepts 2 parameters: reason, ms. When called, it returns an abortsignal instance. Understanding when and how to use AbortSignal() helps you write more expressive, readable code.
Common use cases for AbortSignal include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like event-abortcontroller, event-addeventlistener, event-removeeventlistener, enabling you to chain operations together for complex data manipulation pipelines.
AbortSignal.abort() supported in Chrome 93+, Firefox 88+, Safari 15+. AbortSignal.timeout() in Chrome 103+, Firefox 100+, Safari 16+. AbortSignal.any() in Chrome 116+, Firefox 124+, Safari 17.4+.
Browser Compatibility
AbortSignal.abort() supported in Chrome 93+, Firefox 88+, Safari 15+. AbortSignal.timeout() in Chrome 103+, Firefox 100+, Safari 16+. AbortSignal.any() in Chrome 116+, Firefox 124+, Safari 17.4+.
Related Methods
AbortControllerCreates a new AbortController instance that can be used to abort one or more web requests as and when desired
EventTarget.prototype.addEventListenerRegisters an event handler of a specific event type on the EventTarget
EventTarget.prototype.removeEventListenerRemoves an event listener previously registered with addEventListener from the EventTarget
More AbortController Methods
Other methods in the AbortController object
Related Tools
More AbortController Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.