Starving the loop — interactive event loop example
1function feedVIPs() {2 queueMicrotask(feedVIPs);3}4 5setTimeout(() => {6 console.log('my table?!');7}, 0);8 9queueMicrotask(feedVIPs);A 0ms setTimeout — should run almost immediately. Watch what actually happens to it.
1 / 8
Call stack
script
Web APIs — browser land
timeout cb 0ms
The event loop — is the call stack empty? → drain the microtask queue first → then take one callback.
Microtask queue — priority
Callback queue
Console
Fig. — Starving the loop · step 1 of 8
← → step · space play · 123 level