Comparison
Event loopvsMicrotask
Event loop
one thread sits in a loop pulling ready events off a queue and running the callback for each one.
The execution model behind Node.js, nginx and most async runtimes: a single thread dispatching completed I/O events to handlers. It removes locking within the loop, since only one handler runs at a time. It makes any long synchronous computation a full-service outage for the duration, which is why CPU work gets pushed to a worker pool.
Full entry →Microtask
the promise callback ran before the timeout you scheduled first, and before the browser painted anything.
A callback queued by a resolved promise, `queueMicrotask` or a mutation observer, which runs after the current task and before the browser gets a chance to render. The entire microtask queue is drained each time, including microtasks queued by microtasks, so a promise chain that keeps resolving can starve rendering indefinitely. That ordering — all microtasks, then render, then the next task — is the actual answer to why promise callbacks beat timers.
Full entry →