Node.js Event Loop Explained
Вставка
- Опубліковано 10 гру 2024
- How does the event loop in Node.js work, what are the phases of the event loop and what is the precedence? What is process.nextTick(), what are microtasks and microtasks in Node.js?
======⚡⚡⚡======
Consider becoming a member of the channel by joining me ❤️
/ @softwaredeveloperdiaries
☕ Buy me a coffee: www.buymeacoff...
🙌 Become my Patreon and get exclusive perks: / softdevdiaries
💼 Follow me on LinkedIn and drop me a message if you'd like: / gadirovgs
💻 Also, let's connect on GitHub: github.com/gusgad
📚 Resources:
nodejs.org/en/...
dev.to/jeetvor...
And don't forget to subscribe for more videos like this 😊
This is kind of tutorial I am looking for. Subscribed for more.
wow. I read the official doc and was perplexing for an hour straight. and you smashed it in 10 mins. just wow. you've earn 1 more sub.
Happy to hear that! 😊
The most important discovery for me is the following:
When we think about event loop, we are trying to define one point of view and order things depending on that, but in fact, this diagram shows, that there are at least two of them.
Let me explain what I mean:
So from the application point of view, your loop starts from TIMERS step, it executes Timers, Pending callbacks, idle + prepare, and only after that your app is ready for POLL
But when we think on request processing level, our event loop first step is POLL and moves forward to check and close callbacks, then loops back to timers.
That's why we think that timers are under prioritized by the system, because our point of view in most cases stands on poll stage. And from that point of view that's correct, your set timeout will be handled later.
Close callbacks, per my understanding needs more examples. Because how the regular http request works? We open connection, and then we close the http connection, not only socket connection. So by keeping that in mind, we can understand that our timers will execute when we already sent response and closed the connection.
P.S. Guys, this is how I understand this, and my thoughts can be mistaken, so please improve me if I'm wrong.
every time I look such videos, I discover more and more, and understanding it better and better. so thanks a lot for your work!!! really best explanation maybe "on the market"
Thanks a lot, amigo! ❤️
setTimeout 1
nextTick 1
Promise 1
Promise 2
queueMT 1
setTimeout 2
setTimeout 3
Great explaining try to make a video on worker threads and clusters too that can help to understand use of multi core for optimization
Already have, check out the Node.js playlist 😉
When you dropped a video on Event Driven Architecture I asked for implementation some of its parts please do consider my request make something on implementation of EDA
Bruh your voice 😮💨🔥
So cool!
great content
Thank you!
Thanks❤
Thank you
Under the Huth 😁