@azerum/ts-csp
    Preparing search index...

    Function returnOnAbort

    • 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:

      Listener is removed once select completes:

      await select({ 
      aborted: returnOnAbort(mySignal),
      someOtherOp: something,
      })

      Listener is not removed until mySignal aborts:

      await select({ 
      aborted: returnOnAbort(mySignal)(),
      someOtherOp: something,
      })

      In former we pass (cancelSignal?: AbortSignal) => Promise<unknown>, which allows cancellation via cancelSignal. In later we pass Promise<unknown>, which cannot be cancelled

      Parameters

      • signal: AbortSignal

      Returns (cancelSignal?: AbortSignal) => Promise<unknown>