Class AbortablePromise<T>

The promise that can be aborted.

Type Parameters

  • T

    The value that the promise is resolved with.

Hierarchy

Constructors

Accessors

Methods

Constructors

  • Creates a new abortable promise.

    Type Parameters

    • T

      The value that the promise is resolved with.

    Parameters

    • executor: ((resolve, reject, signal) => void)

      A callback that initializes the promise.

        • (resolve, reject, signal): void
        • Parameters

          • resolve: ((value) => void)

            The resolve callback used to resolve the promise with a value or the result of another promise.

            Param: value

            The fulfillment result.

              • (value): void
              • Parameters

                Returns void

          • reject: ((reason?) => void)

            The reject callback used to reject the promise with a provided reason or error.

            Param: reason

            The rejection reason.

              • (reason?): void
              • Parameters

                • Optional reason: any

                Returns void

          • signal: AbortSignal

            The signal that is aborted if abort method is called.

          Returns void

    Returns AbortablePromise<T>

Accessors

  • get [species](): PromiseConstructor
  • Returns PromiseConstructor

Methods

  • Aborts the signal passed to the executor and instantly rejects the promise with the reason.

    Parameters

    • Optional reason: unknown

      The abort reason. If not explicitly provided, it defaults to an AbortError.

    Returns void

  • Subscribes this promise to be aborted when the signal is aborted.

    Parameters

    • signal: AbortSignal

      The signal that aborts this promise.

    Returns this

    This promise.