JavaScript
async/await
asynchronous programming
programming errors
debugging

Why the execution doesn't stop at await async/await JS?

Master System Design with Codemia

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

Introduction

await does not freeze JavaScript the way a blocking sleep call would in some other languages. It pauses only the current async function and returns control to the event loop, which is why other code can keep running while that function waits for a promise to settle.

await Suspends One Function, Not the Whole Runtime

An async function is still just a function that returns a promise. When JavaScript reaches await, it splits the function into two phases:

  • everything before the await runs now
  • everything after the await is scheduled to continue later

That is why this code logs in an order many beginners do not expect:

javascript
1async function demo() {
2  console.log("inside before await");
3  await Promise.resolve("done");
4  console.log("inside after await");
5}
6
7console.log("script start");
8demo();
9console.log("script end");

The output is:

text
1script start
2inside before await
3script end
4inside after await

Only demo() pauses. The surrounding script continues immediately.

The Event Loop Keeps the Program Moving

JavaScript is designed around an event loop. Network requests, timers, UI events, and promise continuations are all scheduled rather than handled with blocking waits.

So when you write:

javascript
await fetch("/api/data");

JavaScript does not stop the browser tab or Node.js process. It says, in effect, "resume this async function after the promise resolves." While that promise is pending, the runtime can keep handling:

  • other synchronous code that is already running
  • timers
  • user input
  • other promise callbacks

That behavior is what keeps JavaScript environments responsive.

The Caller Must await Too If It Should Pause

Another common source of confusion is the calling function. If one async function calls another without awaiting it, the caller continues immediately.

javascript
1function delay(ms) {
2  return new Promise((resolve) => setTimeout(resolve, ms));
3}
4
5async function fetchData() {
6  await delay(500);
7  console.log("data loaded");
8}
9
10async function pageLogic() {
11  fetchData();
12  console.log("page shell rendered");
13}
14
15pageLogic();

Here, pageLogic() does not wait for fetchData() because the call is not awaited. If the caller should pause, the caller must also use await:

javascript
1async function pageLogic() {
2  await fetchData();
3  console.log("page shell rendered");
4}

That is often the real explanation when someone says execution "doesn't stop" at await.

await Resumes in a Later Microtask

Even if the awaited promise is already resolved, the code after await does not continue in the same synchronous turn. The continuation is queued as a microtask.

javascript
1async function order() {
2  console.log("A");
3  await Promise.resolve();
4  console.log("B");
5}
6
7order();
8console.log("C");

The output is:

text
A
C
B

This is why await Promise.resolve() can still change execution order even though the promise is already fulfilled.

await Is Not a Global Pause Button

It helps to think of await as syntax for promise continuation, not as a stop-the-world instruction. If JavaScript blocked the entire runtime every time a network request or timer was awaited, browsers would freeze and servers would stop processing unrelated work.

That is exactly the problem async programming is trying to avoid.

Common Pitfalls

  • Expecting await to block all JavaScript instead of only the current async function.
  • Forgetting to await the async function call in the caller.
  • Reading log output as if promise continuations run in the same synchronous step.
  • Using await as though it were a sleep function that halts timers, UI events, and other callbacks.
  • Mixing synchronous mental models with event-loop behavior and then misdiagnosing correct async output as a bug.

Summary

  • 'await pauses one async function, not the entire JavaScript runtime.'
  • Control returns to the event loop while the awaited promise is pending.
  • Code outside the paused async function can keep running.
  • If the caller should wait too, the caller must also use await.
  • Promise continuations after await run later through JavaScript scheduling, even when the promise resolves quickly.

Course illustration
Course illustration

All Rights Reserved.