A utility class used to signal cancelation in selected Promise-based APIs.\nThe API is based on the Web API AbortController.
Promise
AbortController
const ac = new AbortController();\n\nac.signal.addEventListener('abort', () => console.log('Aborted!'),\n { once: true });\n\nac.abort();\n\nconsole.log(ac.signal.aborted); // Prints True\n
Triggers the abort signal, causing the abortController.signal to emit\nthe 'abort' event.
abortController.signal
'abort'
The AbortSignal is used to notify observers when the\nabortController.abort() method is called.
AbortSignal
abortController.abort()
Returns a new already aborted AbortSignal.
Returns a new AbortSignal which will be aborted in delay milliseconds.
delay
The 'abort' event is emitted when the abortController.abort() method\nis called. The callback is invoked with a single object argument with a\nsingle type property set to 'abort':
type
const ac = new AbortController();\n\n// Use either the onabort property...\nac.signal.onabort = () => console.log('aborted!');\n\n// Or the EventTarget API...\nac.signal.addEventListener('abort', (event) => {\n console.log(event.type); // Prints 'abort'\n}, { once: true });\n\nac.abort();\n
The AbortController with which the AbortSignal is associated will only\never trigger the 'abort' event once. We recommended that code check\nthat the abortSignal.aborted attribute is false before adding an 'abort'\nevent listener.
abortSignal.aborted
false
Any event listeners attached to the AbortSignal should use the\n{ once: true } option (or, if using the EventEmitter APIs to attach a\nlistener, use the once() method) to ensure that the event listener is\nremoved as soon as the 'abort' event is handled. Failure to do so may\nresult in memory leaks.
{ once: true }
EventEmitter
once()
An optional callback function that may be set by user code to be notified\nwhen the abortController.abort() function has been called.
An optional reason specified when the AbortSignal was triggered.
const ac = new AbortController();\nac.abort(new Error('boom!'));\nconsole.log(ac.signal.reason); // Error('boom!');\n
If abortSignal.aborted is true, throws abortSignal.reason.
true
abortSignal.reason
Used to handle binary data. See the buffer section.
clearImmediate is described in the timers section.
clearImmediate
clearInterval is described in the timers section.
clearInterval
clearTimeout is described in the timers section.
clearTimeout
Used to print to stdout and stderr. See the console section.
console
A browser-compatible implementation of the CustomEvent Web API.
CustomEvent
A browser-compatible implementation of the Event class. See\nEventTarget and Event API for more details.
Event
EventTarget
A browser-compatible implementation of the EventTarget class. See\nEventTarget and Event API for more details.
In browsers, the top-level scope is the global scope. This means that\nwithin the browser var something will define a new global variable. In\nNode.js this is different. The top-level scope is not the global scope;\nvar something inside a Node.js module will be local to that module.
var something
The MessageChannel class. See MessageChannel for more details.
MessageChannel
The MessageEvent class. See MessageEvent for more details.
MessageEvent
The MessagePort class. See MessagePort for more details.
MessagePort
The process object. See the process object section.
process
callback
The queueMicrotask() method queues a microtask to invoke callback. If\ncallback throws an exception, the process object 'uncaughtException'\nevent will be emitted.
queueMicrotask()
'uncaughtException'
The microtask queue is managed by V8 and may be used in a similar manner to\nthe process.nextTick() queue, which is managed by Node.js. The\nprocess.nextTick() queue is always processed before the microtask queue\nwithin each turn of the Node.js event loop.
process.nextTick()
// Here, `queueMicrotask()` is used to ensure the 'load' event is always\n// emitted asynchronously, and therefore consistently. Using\n// `process.nextTick()` here would result in the 'load' event always emitting\n// before any other promise jobs.\n\nDataHandler.prototype.load = async function load(key) {\n const hit = this._cache.get(key);\n if (hit !== undefined) {\n queueMicrotask(() => {\n this.emit('load', hit);\n });\n return;\n }\n\n const data = await fetchData(key);\n this._cache.set(key, data);\n this.emit('load', data);\n};\n
setImmediate is described in the timers section.
setImmediate
setInterval is described in the timers section.
setInterval
setTimeout is described in the timers section.
setTimeout
The WHATWG TextDecoder class. See the TextDecoder section.
TextDecoder
The WHATWG TextEncoder class. See the TextEncoder section.
TextEncoder
The WHATWG URL class. See the URL section.
URL
The WHATWG URLSearchParams class. See the URLSearchParams section.
URLSearchParams
The object that acts as the namespace for all W3C\nWebAssembly related functionality. See the\nMozilla Developer Network for usage and compatibility.
Global alias for buffer.atob().
buffer.atob()
Global alias for buffer.btoa().
buffer.btoa()
This variable may appear to be global but is not. See require().
require()
These objects are available in all modules. The following variables may appear\nto be global but are not. They exist only in the scope of modules, see the\nmodule system documentation:
__dirname
__filename
exports
module
The objects listed here are specific to Node.js. There are built-in objects\nthat are part of the JavaScript language itself, which are also globally\naccessible.
This variable may appear to be global but is not. See __dirname.
This variable may appear to be global but is not. See __filename.
A browser-compatible implementation of <Crypto>. This global is available\nonly if the Node.js binary was compiled with including support for the\nnode:crypto module.
node:crypto
A browser-compatible implementation of the Web Crypto API.
A browser-compatible implementation of <CryptoKey>. This global is available\nonly if the Node.js binary was compiled with including support for the\nnode:crypto module.
This variable may appear to be global but is not. See exports.
A browser-compatible implementation of the fetch() function.
fetch()
A browser-compatible implementation of <FormData>.
A browser-compatible implementation of <Headers>.
This variable may appear to be global but is not. See module.
The perf_hooks.performance object.
perf_hooks.performance
A browser-compatible implementation of <Response>.
A browser-compatible implementation of <Request>.
A browser-compatible implementation of <SubtleCrypto>. This global is available\nonly if the Node.js binary was compiled with including support for the\nnode:crypto module.