Class CancellablePromise<T>

This example shows off how TypeDoc handles

  • Complex method signatures
  • Static methods
  • A method with 10 overload signatures. Wow!
    • Only the implementation signature has a doc comment. TypeDoc automatically copies the comment from the implementation signature to each of the visible signatures if they don't have one.

A promise with a cancel method. If canceled, the CancellablePromise will reject with a Cancellation object. Originally from real-cancellable-promise.

Type Parameters

  • T

    what the CancellablePromise resolves to

Constructors

Properties

Methods

Descriptions can be added for groups with @groupDescription, which will show up in the index where groups are listed. This works for both manually created groups which are created with @group, and implicit groups like the Methods group that this description is attached to.

Constructors

Properties

promise: Promise<T>

As a consumer of the library, you shouldn't ever need to access CancellablePromise.promise directly.

If you are subclassing CancellablePromise for some reason, you can access this property.

cancel: ((reason?) => void)

Cancel the CancellablePromise.

Type declaration

    • (reason?): void
    • Parameters

      • Optional reason: string

      Returns void

Methods

  • Analogous to Promise.then.

    onFulfilled on onRejected can return a value, a normal promise, or a CancellablePromise. So you can make a chain a CancellablePromises like this:

    const overallPromise = cancellableAsyncFunction1()
    .then(cancellableAsyncFunction2)
    .then(cancellableAsyncFunction3)
    .then(cancellableAsyncFunction4)

    Then if you call overallPromise.cancel, cancel is called on all CancellablePromises in the chain! In practice, this means that whichever async operation is in progress will be canceled.

    Type Parameters

    • TResult1 = T
    • TResult2 = never

    Parameters

    Returns CancellablePromise<TResult1 | TResult2>

    a new CancellablePromise

  • Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.

    Parameters

    • Optional onFinally: null | (() => void)

      The callback to execute when the Promise is settled (fulfilled or rejected).

    Returns CancellablePromise<T>

    A Promise for the completion of the callback.

  • Creates a CancellablePromise that is resolved with an array of results when all of the provided Promises resolve or reject.

    Type Parameters

    • T extends readonly unknown[] | readonly [unknown]

    Parameters

    • values: T

      An array of Promises.

    Returns CancellablePromise<{
        -readonly [P in string | number | symbol]: PromiseSettledResult<T[P<P>] extends PromiseLike<U>
            ? U
            : T[P<P>]>
    }>

    A new CancellablePromise.

  • Creates a CancellablePromise that is resolved with an array of results when all of the provided Promises resolve or reject.

    Type Parameters

    • T

    Parameters

    • values: Iterable<T>

      An array of Promises.

    Returns CancellablePromise<PromiseSettledResult<T extends PromiseLike<U>
        ? U
        : T>[]>

    A new CancellablePromise. Canceling it cancels all of the input promises.