.then after .then — interactive event loop example
1Promise.resolve()2 .then(() => {3 console.log('first');4 })5 .then(() => {6 console.log('second');7 });8 9console.log('sync');The chain is built synchronously, but only the first .then callback is queued now. The second waits — its promise hasn't resolved yet.
1 / 7
Call stack
script
Web APIs — browser land
The event loop — is the call stack empty? → drain the microtask queue first → then take one callback.
Microtask queue — priority
then #1
Callback queue
Console
Fig. — .then after .then · step 1 of 7
← → step · space play · 123 level