Lesson 8
Concurrency with Promise.all
Build a practical mental model for concurrency with promise.all and use it in working JavaScript.
By the end, you will be able to…
- Explain concurrency with promise.all in your own words
- Use concurrency with promise.all in a small program
- Recognize and debug a common failure mode
Build the mental model
Promise.all runs independent async operations concurrently instead of one after another, resolving with all their results in order once every one of them succeeds — or rejecting immediately if any one fails.
Syntax and working example
Read the code from inputs to output. Predict what it prints, then run it and change one value.
Why this matters
Awaiting independent requests sequentially wastes time; running them concurrently with Promise.all can cut real load time roughly in half or more.
Real-world example
A profile page loading user info and their posts at the same time, instead of waiting for one before starting the other.
Common mistakes
- Awaiting independent requests one after another (sequentially) when they could run concurrently
- Not realizing Promise.all rejects entirely if even one input rejects, losing the other results
- Reaching for Promise.all when Promise.allSettled is what's actually needed (to tolerate partial failure)
Try it yourself
Challenge
Write loadAll(fetchers) that runs an array of functions returning Promises concurrently.
Knowledge check
What happens if one of several Promises passed to Promise.all rejects?
Summary
Use Promise.all to run independent async work concurrently; use Promise.allSettled when partial failure is acceptable.