Loading topic
async/await, try/catch, and basic addEventListener usage. Every example runs in a modern browser console or in Node.js 18 or later, where AbortController and AbortSignal are globals.4 min readAbortSignal is a small object that answers two questions for any code holding it: has cancellation been requested, and why? It answers them through two read-only properties, aborted and reason. Every cancellable function you write in this tutorial reads these properties, so you need to know4 min readsignal.aborted and signal.reason at a moment it chose. That approach covers checks at the start of a function or between steps. It does nothing for work that is waiting, such as a pending timer, an open socket, or a callback that has not fired yet. You5 min readsignal property inside an options object. Getting the details right means your function behaves like fetch, addEventListener, and 4 min readAbortController, read signal.aborted and signal.reason, and listen for the abort event, all covered in earlier chapters. You should also be comfortable with promises, async/await, and try/catch.5 min readnew Promise((resolve, reject) => ...), how setTimeout and clearTimeout work, and the basics of AbortSignal from earlier chapters: signal.aborted, signal.reason, the abort event, and the convention of accepting { signal } i5 min readasync/await, for...of loops, and try/catch. It also assumes you know the signal.aborted and signal.reason properties and the optional { signal } options convention from earlier chapters.5 min read{ signal } = {} in its options object, check signal.aborted at the start, and add cancellation checkpoints with signal.throwIfAborted(). It also assumes you know how fetch and async/await work.5 min readsignal.aborted says cancellation happened, and signal.reason says why. This chapter covers the second part: which values reason can hold, where they come from, and how your own functions should pass them on so callers get useful errors.4 min readasync/await, try/catch,5 min readcontroller.abort(). Plenty of work also needs to stop when time runs out, even if nobody asks. A request that hangs for two minutes is usually worse than one that fails after five seconds. This chapter shows how to add deadlin5 min readsignal option, but fetch and your own cancellable f5 min readaddEventListener and removeEventListener, closures, and the AbortController basics from earlier chapters. The examples use the standard EventTarget class. It exists in browsers and in Node.js 15 and later, so you can run every snippet in Node without a DOM.4 min read