durable-execution - v0.8.0
    Preparing search index...

    Function createCancellablePromise

    • Create a cancellable promise. If a signal is provided, the promise will be rejected with a DurableTaskCancelledError if the signal is cancelled.

      Type Parameters

      • T

      Parameters

      • promise: Promise<T>

        The promise to cancel.

      • Optionalsignal: CancelSignal

        A signal to cancel the promise.

      • OptionalcancelledError: Error

        An optional error to use when the promise is cancelled. If not provided, a DurableTaskCancelledError will be used. If the error is a DurableTaskError, it will be returned as is, otherwise a DurableTaskCancelledError will be created with the error message.

      Returns Promise<T>

      A promise that will be rejected with a DurableTaskCancelledError if the signal is cancelled.

      const [cancelSignal, cancel] = createCancelSignal()
      const promise = createCancellablePromise(doSomething(), cancelSignal)

      cancel() // Cancels the promise if it is not already resolved