Bigger Picture Of Node Event Loops

Image result for event loop in node js

Even though you are a beginner for node js you all know that Node.js is single threaded.But we use Node.js for powerful backends and we can include concurrence functionality into a Node.js application using events and call backs.In simple terms 'Event Loop' is what permits Node.js to perform non blocking I/O operations.Node.js uses event in large scale and it is the reason behind the speed when comparing to other technologies in the same stack

Image result for event loop in node js


What exactly is 'Event Loop' ? Everything happens in Node.js platform is because of events.'Event Loop' mechanism is inside the library called 'Libuv'.Since there is only one thread both userland code (code of the user) and event loop run in that same thread.Every callback is handled by the so called mechanism 'Event Loop'.Every userland code running in a Node application is a callback.Event Loop is behind the huge success of Node.js development.As I mentioned earlier every Node application is single threaded and what we should be careful when writing the application is not to block the thread.Most of the browsers now have a Event loop for each and every browser tab.It will isolate each and every process and it will stop crashing when a application is executing an infinite loop or heavy processing.

Now I am going to  dive into the process inside the Event Loop.When a Node applications starts it will automatically initialise an Event Loop.We can identify six phases inside the process of an Event Loop.

Image result for event loop phases

  1. Timers - Execute Callbacks scheduled by setTimeout() and setInterval()
  2. I / O Callbacks - Execute I/O Callbacks
  3. Idle, Prepare - This is the only internal phase
  4. Poll - Retrieve new I/O events and execute I/O related Callbacks
  5. Check - Invoke setImmediate() Callbacks
  6. Close - Invoke close Callbacks
In here I tried  to convey the importance of Event Loop and give you a brief idea about it.The post below is about common misconceptions related to Event Loop.


Thank you for being with D Guides.Be safe until we meet again.

Comments

Popular posts from this blog

Deep Dive Into Azure Global Infrastructure

Useful Tools For React Developers