In this lesson, we introduce the process object, part of the node.js global namespace. The process object is extremely useful for identifying information about the runtime environment of your node app such as the version of node, the arguments passed to the node executable, the current working directory, and the nextTick function. All of these are discussed and illustrated with examples in this lesson.
Nice tutorial. But it's a bit tricky with non native English user like me. So I have to read the transcript several times to understand. I suggest that we should have diagram or some graphs to make concept/idea clearer
here is the compare between setTimeout and nextTick
https://gist.github.com/wyvernnot/f406b3276f667f989ac984b61034058e
at 4:22 there is a ')' missing in the tick.js file to close the process.nextTick( -> SyntaxError: missing ) after argument list
Could you explain the I/O overhead part? We gloss over that but this is a fundamentals course, that seems pretty fundamental to me. Thanks!
Could you explain the I/O overhead part? We gloss over that but this is a fundamentals course, that seems pretty fundamental to me. Thanks!
I second this!
Could you explain the I/O overhead part? We gloss over that but this is a fundamentals course, that seems pretty fundamental to me. Thanks!
I second this!
I third this!
From what I understood after reading the docs https://nodejs.org/es/docs/guides/event-loop-timers-and-nexttick what he meant by "I/O overhead" is that the time we use as threshold for timers is not guaranteed since node's event loop could be in poll phase
checking and executing callbacks related to I/O (reading files, api calls, etc.) which by then have higher priority and could take longer than the time we expect our timer's callbacks to run. Only after the poll queue is empty the event loop will check for timers whose time thresholds have been reached and if one or more timers are ready, the event loop will wrap back to the timers phase to execute those timers' callbacks.
On the other side callbacks passed to process.nextTick()
will be added to the nextTickQueue
which will be processed after the current operation is completed regardless of the current phase of the event loop and every time before it continues to the next phase.
The key to get this is to know each phase has a queue of callbacks and timer's queue have their turn (phase) on node's event loop priorities but since the nextTickQueue
is evaluated more often (on each phase before proceeding to the next one) callbacks passed to process.nextTick()
will have higher priority.