Parallel Promises
Promise.all runs promises in parallel and resolves when all succeed (or rejects on first failure). Promise.allSettled waits for all regardless of outcome.
Promise.all runs promises in parallel and resolves when all succeed (or rejects on first failure). Promise.allSettled waits for all regardless of outcome.
const [user, posts, comments] = await Promise.all([
fetch("/api/user").then(r => r.json()),
fetch("/api/posts").then(r => r.json()),
fetch("/api/comments").then(r => r.json()),
]);
// Never fails — inspect each result
const results = await Promise.allSettled([p1, p2, p3]);
results.forEach(({ status, value, reason }) => { /* ... */ });
Promise.all fails fast — use Promise.allSettled when you need all results even if some fail.
More in JavaScript