Waits for signal to abort, resolves with signal.reason when it is aborted.
The wait can be cancelled by providing a second signal - cancelSignal.
When cancelSignal is cancelled, promise rejects with AbortedError
Any listeners added on both signal and cancelSignal are
always removed by the time the promise is settled - no leaks
Note that this function is curried - returnOnAbort(signal)(cancelSignal)
instead of returnOnAbort(signal, cancelSignal). This is to encourage cleanup
of listeners when using it with select. Compare:
In former we pass (cancelSignal?: AbortSignal) => Promise<unknown>, which
allows cancellation via cancelSignal. In later we pass Promise<unknown>,
which cannot be cancelled
Waits for
signalto abort, resolves withsignal.reasonwhen it is aborted. The wait can be cancelled by providing a second signal -cancelSignal. WhencancelSignalis cancelled, promise rejects withAbortedErrorAny listeners added on both
signalandcancelSignalare always removed by the time the promise is settled - no leaksNote that this function is curried -
returnOnAbort(signal)(cancelSignal)instead ofreturnOnAbort(signal, cancelSignal). This is to encourage cleanup of listeners when using it with select. Compare:Listener is removed once select completes:
Listener is not removed until
mySignalaborts:In former we pass
(cancelSignal?: AbortSignal) => Promise<unknown>, which allows cancellation viacancelSignal. In later we passPromise<unknown>, which cannot be cancelled