Promise.allSettled: Waiting for All Results
You'll learn how Promise.allSettled() waits for every promise to complete, giving you results for both successes and failures.
What's the Difference?
You already know Promise.all() fails fast—if one promise rejects, the whole thing rejects immediately. But what if you want to try multiple operations and see all the outcomes, regardless of whether some failed?
That's exactly what Promise.allSettled() does. It waits for every promise to settle (either fulfilled or rejected) and gives you an array describing each result.
How It Works
const promises = [
Promise.resolve(42),
Promise.reject('Error!'),
Promise.resolve(100)
];
Promise.allSettled(promises).then(results => {
console.log(results);
// [
// { status: 'fulfilled', value: 42 },
// { status: 'rejected', reason: 'Error!' },
// { status: 'fulfilled', value: 100 }
// ]
});
Each result object has a status property ('fulfilled' or 'rejected'). Fulfilled promises include a value property; rejected ones include a reason property.
When to Use It
Promise.allSettled() is perfect when you need to attempt multiple independent operations and want a complete report:
const imageUploads = [uploadToServer1(), uploadToServer2(), uploadToServer3()];
Promise.allSettled(imageUploads).then(results => {
const succeeded = results.filter(r => r.status === 'fulfilled');
const failed = results.filter(r => r.status === 'rejected');
console.log(`${succeeded.length} uploads succeeded`);
console.log(`${failed.length} uploads failed`);
});
Key Takeaway: Use Promise.allSettled() when you want to wait for all promises to complete and need visibility into every outcome, not just the successes—it never rejects, always giving you a full results array.