Both methods run multiple promises in parallel, but they differ in how they handle errors.
Choosing the right one prevents bugs and missing data in real-world apps.
Promise.all()
- ❌ Stops on the first failure
- Returns results only if all succeed
- Best for critical operations
Promise.all([
fetch("/user"),
fetch("/orders"),
fetch("/payments") // ❌ fails
])
.then(results => {
// never runs
})
.catch(err => {
console.error("Failed:", err);
});
Promise.allSettled()
- ✅ Waits for all promises to finish
- Returns both success and failure results
- Best for non-critical or batch tasks
Promise.allSettled([
fetch("/user"),
fetch("/orders"),
fetch("/payments") // ❌ fails
])
.then(results => {
results.forEach((result, index) => {
if (result.status === "fulfilled") {
console.log(`Request ${index} success`, result.value);
} else {
console.error(`Request ${index} failed`, result.reason);
}
});
});