Promises.allSettled() in JavaScript
🔍 What is Promise.allSettled()?
Promise.allSettled() takes an array of promises and returns a new promise that resolves after all of them settle (either fulfilled or rejected). Unlike Promise.all(), it never short-circuits and gives you the result of each promise.
>>“Give me the full report — successes and failures alike.”
📦 Syntax
Code Snippet
Promise.allSettled([promise1, promise2, promise3])
.then((results) => {
results.forEach((result) => {
if (result.status === "fulfilled") {
console.log("✅", result.value);
} else {
console.log("❌", result.reason);
}
});
});🚀 Example
Mix of Fulfilled and Rejected
const p1 = Promise.resolve("✅ Success A");
const p2 = Promise.reject("❌ Error B");
const p3 = Promise.resolve("✅ Success C");
Promise.allSettled([p1, p2, p3])
.then((results) => {
results.forEach((result, i) => {
console.log(`Promise ${i + 1}:`, result);
});
});Note
💡 Each result is an object with a status of either "fulfilled" or "rejected", and includes either a value or a reason.
📋 Output Structure
Sample Output
[
{ status: "fulfilled", value: "✅ Success A" },
{ status: "rejected", reason: "❌ Error B" },
{ status: "fulfilled", value: "✅ Success C" }
]💼 Use Case: Logging Results Regardless of Success
Promise.allSettled() is great when you want to wait for all tasks to finish but don’t want a single failure to interrupt the rest.
Useful for Multiple API Results
const urls = ["api/a", "api/b", "api/c"];
const requests = urls.map((url) => fetch(url));
Promise.allSettled(requests).then((results) => {
results.forEach((result, index) => {
if (result.status === "fulfilled") {
console.log(`✅ API ${index + 1} success:`, result.value);
} else {
console.warn(`❌ API ${index + 1} failed:`, result.reason);
}
});
});🧠 Key Points
- Waits for all promises to settle — no short-circuiting.
- Returns a result object for every promise, whether fulfilled or rejected.
- Useful for bulk operations, logging, and fault-tolerant systems.
📚 References
>>“When you care about what happened to everything — not just who won.”