Promise.all / any / race / allSettled — choose the right tool
Practice Promise combinators: all, any, race, allSettled. Learn success/failure behavior and when to use each one.
Combinators overview
Goal: Learn four helpers and their behavior.
- all: wait for all; fail fast
- any: first success
- race: first settled (success/error)
- allSettled: results for all

Promise.all basics
Promise.all resolves with an array of results; a single rejection rejects the whole thing.
// Small helpers for examples
function delay(ms, value, shouldFail = false) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
if (shouldFail) reject(new Error(String(value)));
else resolve(value);
}, ms);
});
}
// Promise.all waits for all; rejects fast on first error
Promise.all([
delay(10, "A"),
delay(5, "B")
]).then(function (vals) {
console.log("all:", vals);
});

All lessons in this course
- Event Loop & Task vs Microtask Basics
- Promises — States, Chaining, Error Handling
- Promise.all / any / race / allSettled — choose the right tool