register
register(
signal,callback):AbortRegistration
Defined in: src/register.ts:17
Runs callback with the signal’s reason when signal aborts, like .NET’s CancellationToken.Register.
Works with any AbortSignal (from fetch, a framework, AbortSignal.timeout, …).
- If the signal has already aborted, the callback runs synchronously, now, and its exceptions
propagate to the caller of
register(). - Otherwise it runs once, as an
abortevent listener: an exception it throws is reported like any event-listener exception (in Node, an uncaught exception), so handle errors inside the callback. - Call
unregister()(orusing) on the result when the guarded work finishes.
Parameters
Section titled “Parameters”signal
Section titled “signal”AbortSignal
callback
Section titled “callback”(reason) => void