Promise.all Failure Semantics
What you'll learn: How Promise.all behaves when any of its input promises rejects—it's all-or-nothing.
The Core Idea
In the previous lesson, you saw Promise.all resolve successfully when all promises fulfill. But what happens when one promise rejects?
Promise.all rejects immediately as soon as any input promise rejects. It doesn't wait for the other promises to settle—the moment one fails, the entire operation is considered failed. The rejection reason will be the error from that first rejected promise.
Why This Matters
Think of Promise.all like a group project where everyone must succeed for the team to pass. If even one person fails their part, the whole project fails immediately—you don't keep waiting for the others to finish.
const promise1 = Promise.resolve(10);
const promise2 = Promise.reject(new Error('Oops!'));
const promise3 = Promise.resolve(30);
Promise.all([promise1, promise2, promise3])
.then(results => {
console.log('All succeeded:', results);
})
.catch(error => {
console.error('One failed:', error.message); // Logs: "One failed: Oops!"
});
Even though promise1 and promise3 succeed, promise2 rejects, so the entire Promise.all rejects. The .then() never runs—control jumps straight to .catch().
Important Caveat
The other promises don't get canceled—they continue running in the background. Promise.all just stops paying attention to them once one fails. This is important for understanding side effects: if those promises perform operations, those operations still happen.
Key Takeaway: Promise.all follows fail-fast semantics—the first rejection immediately rejects the entire combined promise, making it unsuitable for scenarios where you need partial results or want all promises to complete regardless of individual failures.