Function subscribeAbort
Parameters
- signal: AbortSignal
An optional AbortSignal to observe.
- onAbort: (reason: any) => void
A callback invoked when the signal is aborted. Receives the abort
reasonif any.
Returns () => void
A function that removes the abort event listener. Safe to call multiple times.
- signal: AbortSignal
Subscribes to an AbortSignal and invokes the provided callback when the signal is aborted.
If the signal is already aborted at the time of subscription the callback is invoked immediately. Otherwise, the callback is registered as a one-time listener for the
abortevent.An unsubscribe function is returned to remove the event listener allowing proper cleanup of resources.
This utility provides a consistent mechanism for integrating cooperative cancellation into long-running operations such as streams, async iterators, and command pipelines.