Sequential vs Parallel Awaits
What you'll learn: How for-await-of processes promises one at a time, unlike Promise.all which runs them in parallel.
The Core Difference
When you use for-await-of, each promise is awaited sequentially — the loop waits for one promise to resolve before moving to the next. This is fundamentally different from Promise.all, which starts all promises at once and waits for them to complete in parallel.
Think of it like this: for-await-of is like standing in line at a coffee shop, serving one customer completely before starting the next. Promise.all is like having multiple baristas working simultaneously on different orders.
Why This Matters
const delays = [
Promise.resolve(1),
Promise.resolve(2),
Promise.resolve(3)
];
// Sequential: waits for each one before starting next
for await (const value of delays) {
console.log(value); // 1, then 2, then 3
}
// Parallel: all start immediately
const results = await Promise.all(delays);
console.log(results); // [1, 2, 3] all at once
If each promise takes 1 second, for-await-of takes 3 seconds total (1+1+1), while Promise.all takes just 1 second (all running together).
When Sequential Makes Sense
Sequential processing is useful when:
- Order matters and each step depends on the previous one
- You want to limit resource usage (don't hammer a server with 100 simultaneous requests)
- You're processing a stream of data as it arrives
Key Takeaway: for-await-of awaits promises one at a time in sequence, while Promise.all runs them all at once in parallel — choose based on whether you need controlled sequential processing or maximum speed.