Node.js
asynchronous programming
async loops
JavaScript
event loop

node.js How asynchronous are Async loops really?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

A JavaScript loop is still a normal synchronous loop unless the code inside it explicitly waits or schedules asynchronous work. The confusing part is that different loop patterns interact with await very differently, so “async loop” can mean serial execution, parallel task creation, or a broken pattern that does not wait at all.

for...of with await Runs Serially

If you write await inside a for...of loop, each iteration waits before the next one starts:

javascript
1async function runSerial(tasks) {
2  for (const task of tasks) {
3    const result = await task();
4    console.log(result);
5  }
6}

This is asynchronous in the sense that each task can perform non-blocking I/O, but the loop itself advances one iteration at a time.

forEach Does Not Await the Callback

A very common mistake is using forEach with an async callback:

javascript
1async function wrong(tasks) {
2  tasks.forEach(async task => {
3    const result = await task();
4    console.log(result);
5  });
6}

forEach does not wait for those async callbacks to finish. The outer function can continue or finish before the tasks complete, which surprises many developers.

Promise.all Starts Work in Parallel

If you want to launch many async operations and wait for all of them together, create the promises and use Promise.all:

javascript
1async function runParallel(tasks) {
2  const promises = tasks.map(task => task());
3  const results = await Promise.all(promises);
4  console.log(results);
5}

This is often what people expect when they ask how asynchronous a loop really is. The loop that creates promises is synchronous, but the operations those promises represent can progress concurrently.

The Loop Is Not the Asynchronous Part

This is the core idea:

  • the loop structure itself is ordinary synchronous control flow
  • the async operations inside it yield back to the event loop when they await I/O or promises
  • your chosen pattern decides whether iterations wait one by one or overlap

So “async loop” is really shorthand for “a loop that creates or awaits asynchronous work,” not a special category of loop implemented by Node.js.

Pick the Pattern by Intent

Use:

  • 'for...of with await for ordered serial processing'
  • 'Promise.all for parallel work when order of completion does not matter'
  • controlled concurrency tools when fully parallel execution would be too much

That last case matters in real systems, because “parallelize everything” can overwhelm databases, APIs, or the local process.

Concurrency Limits Sit Between the Extremes

Many production loops need something between fully serial await and unrestricted Promise.all. A concurrency limiter lets several tasks run at once without allowing the loop to flood downstream services.

Throughput and Ordering Are Different Goals

Some loops need strict ordering, while others only need good throughput. Make that choice explicitly, because the correct loop pattern depends on whether the next iteration may start before the previous one finishes.

Common Pitfalls

  • Using forEach with async callbacks and expecting it to wait.
  • Calling a loop “asynchronous” without deciding whether the work should be serial or parallel.
  • Launching too many concurrent promises at once with Promise.all.
  • Assuming await makes the loop itself parallel. In for...of, it usually makes it sequential.
  • Forgetting that CPU-bound work still blocks JavaScript even inside async functions.

Summary

  • Loops in Node.js are ordinary synchronous control flow.
  • 'await changes how work is sequenced, not the nature of the loop construct itself.'
  • 'for...of with await is usually serial.'
  • 'forEach does not await async callbacks.'
  • 'Promise.all is the common tool when you want overlapping asynchronous work.'

Course illustration
Course illustration

All Rights Reserved.