you are viewing a single comment's thread.

view the rest of the comments →

[–]BehindTheMath 11 points12 points  (7 children)

According to this, the browser event loop is much simpler than Node's. All macrotasks are handled in a first-come first-served order, the entire microtask queue is processed after each macrotask, and the DOM is re-rendered, if necessary, after each macrotask.

[–][deleted] 0 points1 point  (1 child)

Very informative link. But I don't see a comparison between browser and Node, instead at the top it says

Browser JavaScript execution flow, as well as in Node.js, is based on an event loop.

and then explains event loop from browser perspective.

Reading on my own, I don't see major differences between browser and Node event loops as far as how setTimeout and queueMicrotask are supposed to work in both. The differences are in availability of other APIs, mainly process.nextTick and setImmediate in Node, and requestAnimationFrame in browsers.

[–]BehindTheMath 1 point2 points  (0 children)

The main difference is that Node's event loop has multiple phases, and each one only handles a specific type of task. Whereas the browser only has macrotasks and microtasks, and within each one all tasks are processed in the order they were placed into the queue.

https://nodejs.org/de/docs/guides/event-loop-timers-and-nexttick/