#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Asynchronous JavaScript

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

HelperFulfils whenRejects when
Promise.allEvery input fulfilsAny input rejects
Promise.allSettledEvery input settles, either wayNever
Promise.raceThe first input to settle fulfilsThe first input to settle rejects
Promise.anyThe first input fulfilsEvery 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.

Explore Course