Spec-Zone.ru › JavaScript

Promise.allSettled()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It's been available across browsers since July 2020.

The Promise.allSettled() static method takes an iterable of promises as input and returns a single Promise. This returned promise fulfills when all of the input's promises settle (including when an empty iterable is passed), with an array of objects that describe the outcome of each promise.

Try it

const promise1 = Promise.resolve(3);
const promise2 = new Promise((resolve, reject) =>
  setTimeout(reject, 100, "foo"),
);
const promises = [promise1, promise2];

Promise.allSettled(promises).then((results) =>
  results.forEach((result) => console.log(result.status)),
);

// Expected output:
// "fulfilled"
// "rejected"

Syntax

Promise.allSettled(iterable)

Parameters

iterable
An iterable (such as an Array) of promises. These values are awaited, so other thenables are also resolved, while non-thenables are returned as-is.

Return value

A Promise that is:

  • Already fulfilled, if the iterable passed is empty.
  • Asynchronously fulfilled, when all promises in the given iterable have settled (either fulfilled or rejected). The fulfillment value is an array of objects, each describing the outcome of one promise in the iterable, in the order of the promises passed, regardless of completion order. Each outcome object has the following properties:
    status
    A string, either "fulfilled" or "rejected", indicating the eventual state of the promise.
    value
    Only present if status is "fulfilled". The value that the promise was fulfilled with.
    reason
    Only present if status is "rejected". The reason that the promise was rejected with.

    If the iterable passed is non-empty but contains no pending promises, the returned promise is still asynchronously (instead of synchronously) fulfilled.

Description

The Promise.allSettled() method is one of the promise concurrency methods. Promise.allSettled() is typically used when you have multiple asynchronous tasks that are not dependent on one another to complete successfully, or you'd always like to know the result of each promise.

In comparison, the Promise returned by Promise.all() may be more appropriate if the tasks are dependent on each other, or if you'd like to immediately reject upon any of them rejecting.

Examples

Using Promise.allSettled()

Promise.allSettled([
  Promise.resolve(33),
  new Promise((resolve) => setTimeout(() => resolve(66), 0)),
  99,
  Promise.reject(new Error("an error")),
]).then((values) => console.log(values));

// [
//   { status: 'fulfilled', value: 33 },
//   { status: 'fulfilled', value: 66 },
//   { status: 'fulfilled', value: 99 },
//   { status: 'rejected', reason: Error: an error }
// ]

You may also destructure the results to have one variable per settling outcome.

const [status1, status2] = Promise.allSettled([
  Promise.resolve(33),
  new Promise((resolve) => setTimeout(() => resolve(66), 0)),
]);

// status1 = { status: 'fulfilled', value: 33 }
// status2 = { status: 'fulfilled', value: 66 }

If you destructure the result, you must keep the result variables in the same order as the input promises; a mismatch may cause subtle bugs. The Promise.allSettledKeyed() method avoids this problem by associating each input and output with a key.

Specifications

Specification
ECMAScript® 2027 Language Specification
# sec-promise.allsettled

Browser compatibility

Desktop Mobile Server
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on iOS Samsung Internet WebView Android WebView on iOS Bun Deno Node.js
allSettled
76
79
71
63
13
76
79
54
13
12.0
76
13
1.0.0
1.0
12.9.0

See also

  • Polyfill of Promise.allSettled in core-js
  • es-shims polyfill of Promise.allSettled
  • Using promises guide
  • Graceful asynchronous programming with promises
  • Promise
  • Promise.all()
  • Promise.allSettledKeyed()
  • Promise.any()
  • Promise.race()

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API