AbortController
The standard JavaScript object for cancelling asynchronous work: its signal is handed to the work, and calling abort() cancels it.
In more detail
One controller can cancel a fetch, remove event listeners and stop your own loops at once, because they all watch the same signal. abort(reason) records why, and the reason becomes the error the cancelled work rejects with.
Examples
const ctrl = new AbortController(); fetch(url, { signal: ctrl.signal }); ctrl.abort();In Node.js, stream.pipeline(), fs.watch(), timers/promises and events.once() also accept an AbortSignal.Creating a new controller inside an Effect and aborting it in cleanup cancels outdated requests when dependencies change or the component unmounts.const controller = new AbortController(); fetch(url, { signal: controller.signal }); return () => controller.abort();Related terms
- AbortSignal — The object from an AbortController that tells work it has been cancelled, through its aborted flag, its reason and an abort event.
- Fetch API — The standard JavaScript function fetch() for making HTTP requests, built into browsers and current server runtimes, which returns a promise for the response.
- event listener — A function registered with addEventListener that the browser calls whenever a given event happens on an element or on window.
- cancellation — Stopping work that is no longer needed, such as a search request made obsolete by a new keystroke.
- Promise — A JavaScript object that stands for a result that is not ready yet and will later either succeed with a value or fail with an error.
- stream.pipeline() — A Node.js function that connects streams in a chain, handles backpressure, and destroys every stream in the chain if any of them fails.
- fs.watch() — The Node.js function that reports changes to a file or directory using the operating system's notification system.
- race condition — A bug whose outcome depends on the timing of two things happening at once.
- cleanup function — The function an Effect returns so React can undo what the setup did, such as removing a listener or cancelling a request.
Taught in
- requestAnimationFrame vs requestIdleCallback: High-FPS Work — Frontend Architecture & Web Platform
- Cancellation With AbortController And Async Signal Propagation — Frontend Architecture & Web Platform
- Stream Mechanics: Readable Streams & Flowing Modes — Node.js Internals & Backend Services
- Stream Pipelines: pipeline, AbortSignal & Teardown — Node.js Internals & Backend Services
- Directory Traversal: Recursive Readdir & fs.watch — Node.js Internals & Backend Services
- useEffect Lifecycle: Mount, Dependencies, And Cleanup Phases — React 19 & Modern Component Architecture