Running Parallel Promises
When several asynchronous tasks do not depend on each other, there is no reason to wait for one before starting the next. Running promises in parallel means starting all of them at once and then combining their results. JavaScript gives you four static helpers for this: Promise.all(), Promise.allSettled(), Promise.race() and Promise.any(). Each one takes an iterable of promises and returns a single promise, but they differ in when that promise settles and what it holds.
Sequential versus parallel timing
Suppose loading a user takes about one second and loading their notifications also takes about one second. If you await them one after another, the page waits roughly two seconds. If you start both requests together, the total wait is about as long as the slower of the two. The work itself is not faster; you simply stop leaving the network idle.
Promise.all for "I need every result"
Promise.all() fulfils with an array of values in the same order as the input, no matter which promise finished first. It rejects as soon as any one input rejects, using that first reason. Use it when the page cannot render without every piece of data.
async function loadDashboard(userId) {
const [user, orders, alerts] = await Promise.all([
fetch(`/api/users/${userId}`).then(r => r.json()),
fetch(`/api/users/${userId}/orders`).then(r => r.json()),
fetch(`/api/users/${userId}/alerts`).then(r => r.json())
]);
return { user, orders, alerts };
}
Array destructuring pairs nicely with this helper, because the result order matches the order you passed in.
Choosing between the four helpers
| Helper | Fulfils when | Rejects when |
|---|---|---|
Promise.all | Every input fulfils | Any input rejects |
Promise.allSettled | Every input settles, either way | Never |
Promise.race | The first input to settle fulfils | The first input to settle rejects |
Promise.any | The first input fulfils | Every input rejects (with an AggregateError) |
Promise.allSettled() suits batch jobs where partial success is fine, such as sending ten emails and reporting which ones failed. Each result is an object with status set to "fulfilled" or "rejected", plus a value or reason. Promise.race() is often used to add a timeout by racing a request against a timer that rejects. Promise.any() helps when you have mirrors of the same resource and want whichever answers first successfully.
A trap: creating the promises too late
Parallelism comes from starting the work, not from calling Promise.all(). If you write a loop with await inside it, each request starts only after the previous one finished, and wrapping the result afterwards changes nothing. Build the array of promises first, for example with ids.map(id => fetchItem(id)), and await the combined promise once.
Also remember that Promise.all() does not cancel the other tasks when one fails. They keep running in the background; you just stop waiting for them. If that wastes resources, pass an AbortController signal to each fetch() and abort on failure.
Quick recap
Start independent tasks together, pick the helper that matches how you want failure handled, and keep the results in input order with destructuring. Reach for allSettled when one failure should not hide the other results.
Ready to master real-world web development?
Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.