Skip to content
Buy me a coffee

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 abort event 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() (or using) on the result when the guarded work finishes.

AbortSignal

(reason) => void

AbortRegistration