Wait for the promise to resolve or reject, if resolved the callback function will be called with it's value and if rejected the rejectFn will be called with the reason. If the passed promise argument is not a promise the callback will be called synchronously with the value.

The value or promise like value to wait for

The callback to call on the promise successful resolving.

The callback to call when the promise rejects

The callback to call once the promise has resolved or rejected

The passed value, if it is a promise and there is either a resolve or reject handler then it will return a chained promise with the value from the resolve or reject handler (depending whether it resolve or rejects)

let promise = createPromise<number>((resolve, reject) => {
resolve(42);
});

// Handle via a chained promise
let chainedPromise = promise.then((value) => {
// Do something with the value
});

// Handle via doAwait
doAwait(promise, (value) => {
// Do something with the value
});

// It can also handle the raw value, so you could process the result of either a
// synchrounous return of the value or a Promise
doAwait(42, (value) => {
// Do something with the value
});
  • Wait for the promise to resolve or reject, if resolved the callback function will be called with it's value and if rejected the rejectFn will be called with the reason. If the passed promise argument is not a promise the callback will be called synchronously with the value.

    Type Parameters

    • T
    • TResult1 = T
    • TResult2 = never

    Parameters

    Returns TResult1 | TResult2 | Promise<TResult1 | TResult2>

    The passed value, if it is a promise and there is either a resolve or reject handler then it will return a chained promise with the value from the resolve or reject handler (depending whether it resolve or rejects)

    let promise = createPromise<number>((resolve, reject) => {
    resolve(42);
    });

    // Handle via a chained promise
    let chainedPromise = promise.then((value) => {
    // Do something with the value
    });

    // Handle via doAwait
    doAwait(promise, (value) => {
    // Do something with the value
    });

    // It can also handle the raw value, so you could process the result of either a
    // synchrounous return of the value or a Promise
    doAwait(42, (value) => {
    // Do something with the value
    });
  • Wait for the promise to resolve or reject, if resolved the callback function will be called with it's value and if rejected the rejectFn will be called with the reason. If the passed promise argument is not a promise the callback will be called synchronously with the value.

    Type Parameters

    • T
    • TResult1 = T
    • TResult2 = never

    Parameters

    Returns TResult1 | TResult2 | PromiseLike<TResult1 | TResult2>

    The passed value, if it is a promise and there is either a resolve or reject handler then it will return a chained promise with the value from the resolve or reject handler (depending whether it resolve or rejects)

    let promise = createPromise<number>((resolve, reject) => {
    resolve(42);
    });

    // Handle via a chained promise
    let chainedPromise = promise.then((value) => {
    // Do something with the value
    });

    // Handle via doAwait
    doAwait(promise, (value) => {
    // Do something with the value
    });

    // It can also handle the raw value, so you could process the result of either a
    // synchrounous return of the value or a Promise
    doAwait(42, (value) => {
    // Do something with the value
    });