Skip to main content

AbortController for Cancelling Fetches

AbortController gives you a signal you can pass to fetch (and many other APIs) to cancel an in-flight request. controller.abort() rejects the fetch promise with an AbortError.The c…

April 26, 2026 JavaScript chris 1 min read REST API

Article takeaway

AbortController gives you a signal you can pass to fetch (and many other APIs) to cancel an in-flight request. controller.abort() rejects the fetch promise with an AbortError.The c…

AbortController gives you a signal you can pass to fetch (and many other APIs) to cancel an in-flight request. controller.abort() rejects the fetch promise with an AbortError.

The classic use case is search-as-you-type: cancel the previous request as soon as the user types another character. Without this you race against your own keystrokes and the latest UI can be overwritten by an older response.

AbortSignal.timeout(ms) gives you a one-liner timeout signal — handy in Node 20 and modern browsers.

Share X / Twitter LinkedIn

Leave a comment

Related Posts