Sharing Top Content from the Angular-sphere.

Node.js event loop workflow & lifecycle in low level

  • So event loop enters the timer phase and checks if anything is there in the timer queue to be executed.
  • After timer phase, event loop will enter the pending i/o phase to check if some callbacks from previous tasks are pending or not in the .
  • When event loop enters the poll phase, it execute the scripts in the , which includes file read response, new socket or http connection requests till the time either the entire queue is exhausted or like other phases, a system dependent max limit.
  • After poll phase event loop will immediately come down to check phase where in the queue there could be callbacks invoked by the api .
  • After completing the tasks in check phase, event loop’s next destination is which handles close or destroy type of callbacks.

JavaScript, Node.js, mongo, react, angular and many more

A year back while describing the differences between setImmediate & process.nextTick, I wrote a bit on the low level architecture of node’s event-loop.

Surprisingly, the readers of that post became more interested about the event-loop part, than the rest of the parts and I have received a lot of responses and queries on the same.

That’s why I’ve decided to come up with a big picture of the low level work flow of node.js event loop.

Well, if I google about , majority of the articles out there does not describe the big picture (they try to describe with a very high level abstraction).

This is a screenshot of google image search with . And majority of the image results here are either wrong or having a very high level view on the actual event loop.

Due to these kind of descriptions, developers often found with some misconceptions and wrong understandings. Below are some of the very common misconceptions.

One of the very common misconceptions is that, the event loop is a part of JavaScript engine (v8, spiderMonkey etc). In reality event-loop is the master which uses the JavaScript engines to execute JavaScript code.

First of all there is no stack. Secondly, the process is complicated and have multiple queues (some queue…

Node.js event loop workflow & lifecycle in low level

Comments are closed, but trackbacks and pingbacks are open.