Promise.all([p1, p2, p3]) when p2 rejects?
Options
- It waits for all, then returns results and errors
- It rejects when p2 rejects; the others keep running (Correct option)
- It ignores p2 and returns the other two results
- It retries p2 until it finally succeeds on its own
Answer
Rejects as soon as p2 rejects (fail-fast); the other promises keep running
Why
Promise.all runs promises in parallel and gives you all results, but if ANY of them fails, the combined promise fails immediately with that error. The others are not cancelled; their results are just ignored.
Use Promise.allSettled to get every result and every error, Promise.race for the first to finish, Promise.any for the first success.
Remember
Promise.all fails fast; allSettled waits for everything.