Skip to content

Promise.all

Promise.all waits for all promises to fulfill. If any promise rejects, the entire Promise.all rejects immediately.

const promises = [
fetch('/api/users').then(r => r.json()),
fetch('/api/posts').then(r => r.json()),
fetch('/api/comments').then(r => r.json())
];
try {
const [users, posts, comments] = await Promise.all(promises);
console.log('All data loaded:', { users, posts, comments });
} catch (error) {
console.error('One request failed:', error);
}
const p1 = Promise.resolve('OK');
const p2 = Promise.reject(new Error('Failed!'));
const p3 = Promise.resolve('Also OK'); // Never reached
Promise.all([p1, p2, p3])
.then(results => console.log(results))
.catch(err => console.log(err.message)); // 'Failed!'
// Promise.all rejects IMMEDIATELY when p2 rejects
// p3 is still pending — its result is lost
  • Loading multiple independent data sets in parallel
  • Performing parallel operations where all must succeed
  • Waiting for several async setup steps before proceeding
  • Resolves with array of results when all promises fulfill
  • Rejects immediately if any promise rejects
  • Results maintain the order of the input array
  • Fail-fast behavior: one failure cancels the whole operation