Course contentsShow
← JavaScript
Lesson 1351 of 2,72330. Async/AwaitFree lesson

The Implicit Microtask Queue

Each await queues a microtask, so control returns to the event loop before resuming the async function.

The Implicit Microtask Queue

You'll learn how await secretly schedules microtasks that pause and resume your async function.

How Await Uses the Microtask Queue

Every time JavaScript encounters an await, it doesn't just freeze your function in place. Instead, it:

  1. Queues a microtask to resume the function after the awaited promise settles
  2. Returns control to the event loop immediately
  3. Comes back to your function when the microtask runs

This happens even if the promise is already resolved. The engine still schedules a microtask to maintain consistent, predictable async behavior.

Why This Matters

Think of await like yielding your spot in line: you step aside (queuing a microtask), let others go (event loop continues), then rejoin when called back. This means:

async function example() {
  console.log('1');
  await Promise.resolve();
  console.log('3');
}

example();
console.log('2');

// Output: 1, 2, 3

After the await, control returns to the main script. The synchronous code (console.log('2')) runs first. Only then does the microtask queue drain, resuming example() to log '3'.

Multiple Awaits = Multiple Microtasks

Each await schedules another microtask:

async function multiple() {
  await Promise.resolve(); // Microtask 1
  await Promise.resolve(); // Microtask 2
  await Promise.resolve(); // Microtask 3
}

The function pauses and resumes three separate times, allowing other code to run between each continuation.

Key Takeaway: Every await implicitly queues a microtask and yields control to the event loop, ensuring async functions play nicely with the rest of your JavaScript code by never blocking synchronous execution.