IT lexicon › Web › AbortController

AbortController

Web På svenska → Updated: 2026-05-30

A web API for aborting ongoing asynchronous operations — primarily fetch calls, but also event listeners and more. You create an AbortController, pass its signal to the operation, and can call abort() at any time to cancel it.

Problem: a started fetch long couldn't be aborted — if the user navigated away or typed a new search before the response came, the old request kept going anyway and could overwrite with stale results (a "race"). AbortController solves it: fetch(url, { signal }), and controller.abort() aborts the request (throwing an AbortError). Use case: abort a search when the user keeps typing, abort on navigation/component unmount, set a timeout (AbortSignal.timeout(5000)), and — a clever trick — remove many event listeners at once by giving them all the same signal and calling abort() once. Win: avoid wasted work, race conditions, and memory leaks. A central tool for robust async code. Related to fetch streaming and requestIdleCallback.

← Back to the lexicon