Globals
signal.throwIfAborted()
Checks cancellation at a cooperative boundary by throwing the stored reason if aborted. It returns normally when active. Check between bounded steps; this method cannot preempt a synchronous function by itself. Tested on Node.js 22.16.0. Example output (one line per entry): ["active", "stop"].
Formal Syntax & Structure
nodejs syntaxnodejs
signal.throwIfAborted()Return Value
undefined
Returns normally or throws the abort reason.
Working Example
Example Snippetnodejs
const c = new AbortController();c.signal.throwIfAborted();console.log('active');c.abort(new Error('stop'));try { c.signal.throwIfAborted();}catch (e) { console.log(e.message);}