Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Hierarchy

  • CancellablePromise

Index

Methods

Static resolve

Static reject

Static all

  • all<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): CancellablePromise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>
  • all<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): CancellablePromise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>
  • all<T1, T2, T3, T4, T5, T6, T7, T8>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): CancellablePromise<[T1, T2, T3, T4, T5, T6, T7, T8]>
  • all<T1, T2, T3, T4, T5, T6, T7>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): CancellablePromise<[T1, T2, T3, T4, T5, T6, T7]>
  • all<T1, T2, T3, T4, T5, T6>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): CancellablePromise<[T1, T2, T3, T4, T5, T6]>
  • all<T1, T2, T3, T4, T5>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): CancellablePromise<[T1, T2, T3, T4, T5]>
  • all<T1, T2, T3, T4>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): CancellablePromise<[T1, T2, T3, T4]>
  • all<T1, T2, T3>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): CancellablePromise<[T1, T2, T3]>
  • all<T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): CancellablePromise<[T1, T2]>
  • all<T>(values: readonly (T | PromiseLike<T>)[]): CancellablePromise<T[]>
  • Analogous to Promise.all.

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • T5

    • T6

    • T7

    • T8

    • T9

    • T10

    Parameters

    • values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]

      an array that may contain CancellablePromises, promises, thenables, and resolved values

    Returns CancellablePromise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>

    a CancellablePromise, which, if canceled, will cancel each of the promises passed in to CancellablePromise.all.

  • Analogous to Promise.all.

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • T5

    • T6

    • T7

    • T8

    • T9

    Parameters

    • values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]

      an array that may contain CancellablePromises, promises, thenables, and resolved values

    Returns CancellablePromise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>

    a CancellablePromise, which, if canceled, will cancel each of the promises passed in to CancellablePromise.all.

  • Analogous to Promise.all.

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • T5

    • T6

    • T7

    • T8

    Parameters

    • values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]

      an array that may contain CancellablePromises, promises, thenables, and resolved values

    Returns CancellablePromise<[T1, T2, T3, T4, T5, T6, T7, T8]>

    a CancellablePromise, which, if canceled, will cancel each of the promises passed in to CancellablePromise.all.

  • Analogous to Promise.all.

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • T5

    • T6

    • T7

    Parameters

    • values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]

      an array that may contain CancellablePromises, promises, thenables, and resolved values

    Returns CancellablePromise<[T1, T2, T3, T4, T5, T6, T7]>

    a CancellablePromise, which, if canceled, will cancel each of the promises passed in to CancellablePromise.all.

  • Analogous to Promise.all.

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • T5

    • T6

    Parameters

    • values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]

      an array that may contain CancellablePromises, promises, thenables, and resolved values

    Returns CancellablePromise<[T1, T2, T3, T4, T5, T6]>

    a CancellablePromise, which, if canceled, will cancel each of the promises passed in to CancellablePromise.all.

  • Analogous to Promise.all.

    Type parameters

    • T1

    • T2

    • T3

    • T4

    • T5

    Parameters

    • values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]

      an array that may contain CancellablePromises, promises, thenables, and resolved values

    Returns CancellablePromise<[T1, T2, T3, T4, T5]>

    a CancellablePromise, which, if canceled, will cancel each of the promises passed in to CancellablePromise.all.

  • Analogous to Promise.all.

    Type parameters

    • T1

    • T2

    • T3

    • T4

    Parameters

    • values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]

      an array that may contain CancellablePromises, promises, thenables, and resolved values

    Returns CancellablePromise<[T1, T2, T3, T4]>

    a CancellablePromise, which, if canceled, will cancel each of the promises passed in to CancellablePromise.all.

  • Analogous to Promise.all.

    Type parameters

    • T1

    • T2

    • T3

    Parameters

    • values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]

      an array that may contain CancellablePromises, promises, thenables, and resolved values

    Returns CancellablePromise<[T1, T2, T3]>

    a CancellablePromise, which, if canceled, will cancel each of the promises passed in to CancellablePromise.all.

  • Analogous to Promise.all.

    Type parameters

    • T1

    • T2

    Parameters

    • values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]

      an array that may contain CancellablePromises, promises, thenables, and resolved values

    Returns CancellablePromise<[T1, T2]>

    a CancellablePromise, which, if canceled, will cancel each of the promises passed in to CancellablePromise.all.

  • Analogous to Promise.all.

    Type parameters

    • T

    Parameters

    • values: readonly (T | PromiseLike<T>)[]

      an array that may contain CancellablePromises, promises, thenables, and resolved values

    Returns CancellablePromise<T[]>

    a CancellablePromise, which, if canceled, will cancel each of the promises passed in to CancellablePromise.all.

Static allSettled

  • allSettled<T>(values: T): CancellablePromise<{ -readonly [ P in string | number | symbol]: PromiseSettledResult<T[P] extends PromiseLike<U> ? U : T[P]> }>
  • allSettled<T>(values: Iterable<T>): CancellablePromise<PromiseSettledResult<T extends PromiseLike<U> ? U : T>[]>
  • Creates a CancellablePromise that is resolved with an array of results when all of the provided Promises resolve or reject.

    Type parameters

    • T: readonly unknown[] | readonly [unknown]

    Parameters

    • values: T

      An array of Promises.

    Returns CancellablePromise<{ -readonly [ P in string | number | symbol]: PromiseSettledResult<T[P] extends PromiseLike<U> ? U : T[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.

Static race

  • Creates a CancellablePromise that is resolved or rejected when any of the provided Promises are resolved or rejected.

    Type parameters

    • T

    Parameters

    • values: readonly T[]

      An array of Promises.

    Returns CancellablePromise<T extends PromiseLike<U> ? U : T>

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

Static delay

then

  • then<TResult1, TResult2>(onFulfilled?: null | ((value: T) => TResult1 | PromiseLike<TResult1>), onRejected?: null | ((reason: any) => TResult2 | PromiseLike<TResult2>)): CancellablePromise<TResult1 | TResult2>
  • 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

    • Optional onFulfilled: null | ((value: T) => TResult1 | PromiseLike<TResult1>)
    • Optional onRejected: null | ((reason: any) => TResult2 | PromiseLike<TResult2>)

    Returns CancellablePromise<TResult1 | TResult2>

    a new CancellablePromise

catch

  • catch<TResult>(onRejected?: null | ((reason: any) => TResult | PromiseLike<TResult>)): CancellablePromise<T | TResult>

finally

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

Constructors

constructor

  • new CancellablePromise<T>(promise: PromiseLike<T>, cancel: (reason?: string) => void): CancellablePromise<T>
  • Type parameters

    • T

    Parameters

    • promise: PromiseLike<T>

      a normal promise or thenable

    • cancel: (reason?: string) => void

      a function that cancels promise. Calling cancel after promise has resolved must be a no-op.

        • (reason?: string): void
        • Parameters

          • Optional reason: string

          Returns void

    Returns CancellablePromise<T>

Properties

Protected Readonly promise

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.

Readonly cancel

cancel: (reason?: string) => void

Type declaration

    • (reason?: string): void
    • Cancel the CancellablePromise.

      Parameters

      • Optional reason: string

      Returns void

Generated using TypeDoc