Check out a free preview of the full The Hard Parts of Servers & Node.js course
The "Priority of Queue Execution" Lesson is part of the full, The Hard Parts of Servers & Node.js course featured in this preview video. Here's what you'd learn in this lesson:
Will summarizes Node's event loop's priority rules for automatic execution of JavaScript code within the queue system.
Transcript from the "Priority of Queue Execution" Lesson
[00:00:00]
>> Will Sentance: All right people, let's sum it up. Rules for the automatic execution of the JavaScript code by node, because by the way, all of this is built by node with the help of live UV. It's not JavaScript. All of these queues and the event loop are triggering it is all node, not JavaScript, all built in C++.
[00:00:20]
Hold each deferred, I call these deferred functions that we didn't run ourselves at, are gonna be autorun later, they're deferred, delayed, autorun later, in one of the tasks, jeez, when the node background API. These are actually, these C++ features, they're technically known as APIs. Interface is a posh word for, any functionality that's not in my language, but not in my world, but in someone else's.
[00:00:44]
I interface with it. When any of the background nodes in C++ features complete this autorun function don't autorun them. Queue them up to be autorunned, autoran sorry. Autorun. Add the function to the call stack, in other words, execute the function, add it to the call stack, we do this with each of them.
[00:01:05]
Only when the call stack is totally empty, have the event loop be checking for this condition to be true. Prioritize functions in the timer queue. Technically a min-heap, but basically a queue, over the I/O queue, over the check queue, it's known as, over the close queue, and because I wasn't sure I was going to tell you about these two, four, prioritize over all those queues, any functions that were delayed by using a promise which we're not gonna touch on today, but is another way of triggering background work, and instead of autorunning a function autoinserting data into JavaScript, that outruns a function in JavaScript.
[00:01:46]
That function goes in the micro-task cube, but there's two of those. That one goes in B. The number one process of all that we don't even use is process.netFix, any function you pass there. That goes in to the very, very first queue. There we go people. Those are all the rules of node.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops