Promise.allSettled()
Waits for all promises and returns each outcome (fulfilled/rejected).
Promise.allSettled([promise1, promise2, ...])This static page keeps the syntax and examples indexed for search, while the coding app handles interactive exploration and saved references.
What it does
Overview
Waits for all promises and returns each outcome (fulfilled/rejected).
Promise.allSettled() is a static method introduced in ES2020 that returns a promise that resolves after all given promises have either fulfilled or rejected. Unlike Promise.all(), which follows a 'fail-fast' approach and rejects immediately if any input promise fails, allSettled() ensures that every operation in the iterable completes before resolving. This makes it ideal for handling collections of independent asynchronous tasks where the success of one does not depend on the success of others. Each element in the resulting array is an object with a status property ('fulfilled' or 'rejected'). If the status is 'fulfilled', a value property is present; if 'rejected', a reason property provides the error. Performance-wise, it waits for the slowest promise to settle. If an empty iterable is passed, it returns a promise that resolves to an empty array immediately. IE not supported.
Quick reference
Syntax
Promise.allSettled([promise1, promise2, ...])
Inputs
Parameters
See it in practice
Examples
Handling Mixed Success and Failure
var p1 = Promise.resolve(100);
var p2 = Promise.reject(new Error('Operation Failed'));
var p3 = new Promise(function(resolve) { setTimeout(resolve, 100, 'Delayed'); });
Promise.allSettled([p1, p2, p3]).then(function(results) {
results.forEach(function(result) {
console.log(result.status);
});
});"fulfilled" "rejected" "fulfilled"
Demonstrates how allSettled captures both the resolution of p1 and p3 and the rejection of p2 without stopping execution.
Filtering Successful Results from API Calls
var urls = ['/api/items/1', '/api/items/2'];
var requests = urls.map(function(url) { return fetch(url); });
Promise.allSettled(requests).then(function(results) {
var successfulResponses = results
.filter(function(res) { return res.status === 'fulfilled'; })
.map(function(res) { return res.value; });
console.log('Total successful:', successfulResponses.length);
});"Total successful: 2" (if both fetches succeed)
Useful for bulk operations where you want to process whatever succeeded and ignore or log the failures separately.
Edge Case: Empty Iterable
Promise.allSettled([]).then(function(results) {
console.log(Array.isArray(results));
console.log(results.length);
});true 0
Passing an empty array results in an immediately resolved promise with an empty array as the value.
Debug faster
Common Errors
LogicError
Cause: Assuming the returned promise will reject if one of the input promises rejects.
Fix: Remember that Promise.allSettled() itself only rejects if the input is not iterable. Use .then() and inspect the status of individual objects.
Promise.allSettled([Promise.reject('fail')]).catch(function(err) {
// This block will NOT run for the rejected input promise
console.log(err);
});TypeError
Cause: Accessing the 'value' property on a result object without checking its status first.
Fix: Always check if status === 'fulfilled' before accessing 'value', or status === 'rejected' before accessing 'reason'.
Promise.allSettled([p1, p2]).then(function(results) {
results.forEach(function(r) {
// Error: r.value is undefined if the promise was rejected
console.log(r.value.toLowerCase());
});
});Runtime support
Compatibility
Source: MDN Web Docs
Common questions
Frequently Asked Questions
Waits for all promises and returns each outcome (fulfilled/rejected).
iterable: Promises (or values) to await.
LogicError: Remember that Promise.allSettled() itself only rejects if the input is not iterable. Use .then() and inspect the status of individual objects. TypeError: Always check if status === 'fulfilled' before accessing 'value', or status === 'rejected' before accessing 'reason'.