CKTIS / JavaScript
Promise.any — the first successful result
Promise.any accepts an iterable and returns a promise fulfilled with the value of the first fulfillment it observes. Input rejections do not end the wait unless every input rejects; in that case, the result rejects with AggregateError.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
Promise.any(iterable)Promise.any(iterable) is a static Promise method introduced in ECMAScript 2021 (ES12). It accepts a synchronous iterable, such as an array of promises, plain values, or objects with a then method (thenables). Values are converted through Promise.resolve; do not pass functions expecting the method to invoke them.
The returned promise adopts the value of the first fulfillment Promise.any observes, which is not necessarily the fulfillment that happened earliest. If you pass in two ordinary promises that are already fulfilled and the built-in Promise.resolve returns both unchanged, the first in iteration order wins, even if it fulfilled later than the second. The built-in Promise.resolve returns a promise unchanged if its constructor property equals the receiver of the call (the this value); it does not check the promise's realm. If the first promise is from another realm and has its default constructor, the local Promise.resolve wraps it in a new promise. This delays its fulfillment reaction, so the second can win if it is returned unchanged. But if the first promise's constructor property equals the local Promise, the local Promise.resolve returns it unchanged despite its origin. An input rejection can settle Promise.race if it is the first settlement the method observes. With Promise.any, input rejections cause the result to reject with AggregateError only once every input has rejected, including when the sole input rejects. The method does not cancel the remaining operations after success.
If every input rejects, the result rejects with AggregateError. Its errors array contains reasons in input order, not rejection order. Promise.any([]) returns an already-rejected promise with an empty errors array; handlers still execute asynchronously. An error while reading the iterator can also reject the result, without AggregateError.
Use this method when one successful result is enough. Handle total failure with try/catch around await or with .catch(). The language specification does not establish support in a particular browser: check the target environment, for example with typeof Promise.any === "function". Having Node 24 in a repository does not prove browser support.
Examples
async function main() {
const value = await Promise.any([
Promise.reject("offline"),
Promise.resolve("ready")
]);
console.log(value);
try {
await Promise.any([
Promise.reject("first"),
Promise.reject("second")
]);
} catch (error) {
console.log(error instanceof AggregateError);
console.log(JSON.stringify(error.errors));
}
}
main().catch(console.error);Result
ready true ["first","second"]
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.