Back to results for “Async Patterns”
Node.js › Async Patterns

What is the difference between Promise.all(), Promise.allSettled(), Promise.race(), and Promise.any()?

Intermediate

Answer

Promise.all() resolves when every promise in the array resolves, but rejects immediately as soon as any single promise rejects (short-circuiting the rest). Promise.allSettled() always waits for every promise to settle regardless of outcome, returning an array describing each result's status ('fulfilled' or 'rejected') rather than throwing -- useful when you need every result even if some fail. Promise.race() settles as soon as the first promise settles, whether fulfilled or rejected. Promise.any() resolves as soon as the first promise fulfills, only rejecting if every promise rejects.
const results = await Promise.allSettled([
  fetch('/api/a'), fetch('/api/b'), fetch('/api/c')
]);
results.forEach(r => r.status === 'fulfilled' ? console.log(r.value) : console.error(r.reason));

// Promise.race for a timeout pattern
const result = await Promise.race([fetchData(), timeout(5000)]);
Real-world example A dashboard fetching data from five independent microservices uses Promise.allSettled() rather than Promise.all(), so that if one service is temporarily down, the dashboard can still render data from the four services that succeeded instead of failing the entire page load.

Common follow-ups: How would you implement a request timeout using Promise.race()?;What's a scenario where Promise.any() is specifically the right choice over Promise.race()?