Promise class which provides a 'cancel' method. Read more about Promises.

Type Parameters

  • T

Hierarchy (View Summary)

Constructors

  • Creates Promise instances with "cancel" function.

    Type Parameters

    • T

    Parameters

    Returns CancelablePromise<T>

    const p = new CancelablePromise((resolve, reject, onCancelled) => {
    onCancelled(() => {
    doSomething();
    });
    });

    // grab cancel function for later cancellation
    const cancel = p.cancel;

    // now cancel
    cancel();

Properties

cancel: (reason?: string) => ExtendedPromise<unknown>

Cancels the execution of this promise.

Methods

  • Creates promise which fulfills if all other promises are fulfilled. Or rejects if one of the promises rejects.

    Type Parameters

    • T extends [] | readonly unknown[]

    Parameters

    • iterable: T

      Iterable of Promise instances

    Returns ExtendedPromise<{ -readonly [P in string | number | symbol]: Awaited<T[P<P>]> }>

  • Creates a promise that resolves after all of the given promises have either fulfilled or rejected, with an array of objects that each describes the outcome of each promise.

    Type Parameters

    • T

    Parameters

    • iterable: Iterable<T | PromiseLike<T>>

      Iterable of Promise instances

    Returns ExtendedPromise<PromiseSettledResult<Awaited<T>>[]>

  • Promise.any() takes an iterable of Promise objects and, as soon as one of the promises in the iterable fulfills, returns a single promise that resolves with the value from that promise. If no promises in the iterable fulfill (if all of the given promises are rejected), then the returned promise is rejected with an AggregateError, Essentially, this method is the opposite of Promise.all().

    Type Parameters

    • T

    Parameters

    • iterable: (T | PromiseLike<T>)[] | Iterable<T | PromiseLike<T>>

      Iterable of Promise instances

    Returns ExtendedPromise<T>

  • Creates CancelablePromise around the given promise.

    Type Parameters

    • T

    Parameters

    • promise: PromiseLike<T>

      base promise.

    Returns CancelablePromise<T>

    a cancelable promise

  • This method tests if a given object is a promise. The algorithm will return true for:

    • apprt-core/Promise
    • global Promise
    • dojo/Deferred
    • dojo/Deferred.promise

    Note: Because of support for dojo/Deferred any object with a 'then', 'isResolved' and 'isRejected' method is detected as a promise.

    Parameters

    • candidate: any

      a potential promise.

    Returns candidate is PromiseLike<unknown>

    true if candidate is a promise.

  • Creates promise which fulfills if one of the other promises fulfills. Or rejects if one of the promises rejects.

    Type Parameters

    • T

    Parameters

    • iterable: Iterable<T>

      Iterable of Promise instances

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

  • Creates promise which fulfills if one of the other promises fulfills. Or rejects if one of the promises rejects.

    Type Parameters

    • T

    Parameters

    • iterable: Iterable<T | PromiseLike<T>>

      Iterable of Promise instances

    Returns ExtendedPromise<T>

  • Produces an object with a promise along with its resolution and rejection functions. Allows to resolve/reject the promise manually after creating it.

    Type Parameters

    • T

    Returns {
        promise: ExtendedPromise<T>;
        reject: (reason?: unknown) => void;
        resolve: (value: T | PromiseLike<T>) => void;
    }

    const { promise, resolve, reject } = Promise.withResolvers();
    
  • Wraps e.g. dojo/Deferred or native Promise to this Promise class.

    Type Parameters

    • T

    Parameters

    • promise: LegacyDojoDeferred | PromiseLike<T>

    Returns ExtendedPromise<T>

    a promise

  • Registers a handler, which is called in success or error state. But the handler is not able to change the result state!

    Parameters

    • Optionalhandler: null | () => void

      function invoked regardless of success or error

    Returns ExtendedPromise<T>