Function createIdleAnyPromise

The createIdleAnyPromise method takes an array of promises as input and returns a single Promise. This returned promise fulfills when any of the input's promises fulfills, with this first fulfillment value. It rejects when all of the input's promises reject (including when an empty iterable is passed), with an AggregateError containing an array of rejection reasons.

0.5.0

An Array promises.

Optional timeout to wait before processing the items, defaults to zero, only used when Native promises are not available.

A new Promise that is:

  • Already rejected, if the iterable passed is empty.
  • Asynchronously fulfilled, when any of the promises in the given iterable fulfills. The fulfillment value is the fulfillment value of the first promise that was fulfilled.
  • Asynchronously rejected, when all of the promises in the given iterable reject. The rejection reason is an AggregateError containing an array of rejection reasons in its errors property. The errors are in the order of the promises passed, regardless of completion order. If the iterable passed is non-empty but contains no pending promises, the returned promise is still asynchronously (instead of synchronously) rejected.
  • The createIdleAnyPromise method takes an iterable of promises as input and returns a single Promise. This returned promise fulfills when any of the input's promises fulfills, with this first fulfillment value. It rejects when all of the input's promises reject (including when an empty iterable is passed), with an AggregateError containing an array of rejection reasons.

    Type Parameters

    • T

    Parameters

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

      An iterable object of promises.

    • Optionaltimeout: number

      Optional timeout to wait before processing the items, defaults to zero, only used when Native promises are not available.

    Returns IPromise<Awaited<T>>

    A new Promise that is:

    • Already rejected, if the iterable passed is empty.
    • Asynchronously fulfilled, when any of the promises in the given iterable fulfills. The fulfillment value is the fulfillment value of the first promise that was fulfilled.
    • Asynchronously rejected, when all of the promises in the given iterable reject. The rejection reason is an AggregateError containing an array of rejection reasons in its errors property. The errors are in the order of the promises passed, regardless of completion order. If the iterable passed is non-empty but contains no pending promises, the returned promise is still asynchronously (instead of synchronously) rejected.

    0.5.0