Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. Promise
  6. allSettled()

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⁩.

ThePromise.allSettled() static method takes an iterable of promises as input and returns a singlePromise. 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

js
Promise.allSettled(iterable)

Parameters

iterable

Aniterable (such as anArray) of promises.

Return value

APromise that is:

  • Already fulfilled, if theiterable passed is empty.

  • Asynchronously fulfilled, when all promises in the giveniterable have settled (either fulfilled or rejected). The fulfillment value is an array of objects, each describing the outcome of one promise in theiterable, 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 ifstatus is"fulfilled". The value that the promise was fulfilled with.

    reason

    Only present ifstatus is"rejected". The reason that the promise was rejected with.

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

Description

ThePromise.allSettled() method is one of thepromise 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 byPromise.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()

js
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 }// ]

Specifications

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

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp