The Event Loop explained | NodeBook #12
Replies: 2 comments 2 replies
-
|
Where are Macro queue and Micro queue? at V8 or libuv? |
Beta Was this translation helpful? Give feedback.
-
The nextTick queue and the Promise Jobs queue are a bit more interleaved than this list suggests. Consider this example: const process = require("node:process");
Promise.resolve().then(() => {
setTimeout(() => console.log("1"));
process.nextTick(() => console.log("2"));
Promise.resolve().then(() => console.log("3"));
});
process.nextTick(() => {
setTimeout(() => console.log("4"));
process.nextTick(() => console.log("5"));
Promise.resolve().then(() => console.log("6"));
});Based on the steps above, you might expect the order of logs to be In the above example, it might be apparent because the context is explicitly given by nesting jobs, but it might be surprising when switching from CJS to ESM as there the context is implicit: Node processes ESM as part of the microtask queue. In fact, you can change the order of logs in the example from the A Complex Execution Order Analysis section just by switching the module system. If you replace the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The Event Loop explained
Learn and Master the complex parts of the Node.js Runtime. From V8's Turbofan optimizer to production deployments. Each chapter includes hands-on labs, real-world examples, and performance insights. The definitive guide to becoming a Node.js expert.
https://www.thenodebook.com/node-arch/event-loop-intro
Beta Was this translation helpful? Give feedback.
All reactions