The Function Returned. It Wasn't Finished. | async await Internals

Опубликовано: 24 Май 2026
на канале: The Leap
101
6

What actually happens at the await line — the function splits, yields a promise, and resumes later as a microtask. The function returned. It wasn't finished.

You write await and expect the function to pause — stop here, wait, then continue. That's what it looks like. But the system can't stop. Not for one function. Not for anything. So it doesn't pause. It leaves.

This video shows the mechanic: the function splits in two at the await line. The top half runs synchronously. The bottom half becomes a continuation — scheduled later as a microtask. The function returns a promise to its caller, and the event loop keeps moving.

That gap between the two halves? Other code runs there. State can change. Data can shift. Something you checked before the await may no longer be true after.

Topics: async/await internals, function continuation, microtask scheduling, promise mechanics, event loop, JavaScript execution order, Node.js async

This is Episode 07 of The Leap — a series that builds real understanding of async, concurrency, and systems thinking for backend engineers. No frameworks. No shortcuts.

⏱ Timestamps:
0:00 - It returned. It wasn't finished.
0:05 - The function pauses... but something else runs
0:25 - The question: where does the rest go?
0:50 - What you'd expect vs. what actually happens
1:22 - The split
1:47 - The yield — promise, loop, microtask
2:15 - Kitchen analogy — the oven
2:51 - The proof: A, C, B
3:21 - The danger — state changes in the gap
3:49 - The reframe: await is not a pause
4:12 - The full cycle: split, yield, resume
4:30 - Closing
4:47 - What comes next

📌 Key idea:
Stop asking "what does await wait for?"
Start asking "what runs while the function is gone?"

📺 Previous: setTimeout(0) Doesn't Run First —    • setTimeout(0) Doesn't Run First. | Microta...  
📺 Next: Between Two Awaits — the most dangerous place in async code    • The Code Was Correct. Both Times. | A Race...  

──────────────

The Leap is a series for software engineers who want to understand systems deeply — not just use them. No hype. No shortcuts. Just clarity.

If this changed how you think about await — subscribe.

#asyncawait #eventloop #javascript #nodejs #concurrency