async/await, unmasked โ€” interactive event loop example

1async function order() {
2 console.log('ordering');
3 await Promise.resolve();
4 console.log('order arrived');
5}
6
7order();
8console.log('walk away');

Calling an async function is a NORMAL call: order() pushes onto the stack and starts executing synchronously.

1 / 7

Call stack

script
order()

Web APIs โ€” browser land

The event loop โ€” is the call stack empty? โ†’ drain the microtask queue first โ†’ then take one callback.

Microtask queue โ€” priority

Callback queue

Console

Fig. โ€” async/await, unmasked ยท step 1 of 7

โ† โ†’ step ยท space play ยท 123 level