DEV Community


Posted on

Event loop

This is my first dev blogpost and doesn't matter if it is just couple of sentences. Couple of sentences are still better than not writing at all. This week I'm writing brief about Event Loop

Event Loop

Javascript engine runs chunks of JS code on a single thread process. Usually it co-exists with hosting environment like Browser or Node JS. Typical job of the JS engine is to just run the chunks on-demand basis. Overall orchestration of when to run a chunk of code is handled by the hosting environment Event Loop .

Event Loop as the name says it is loop which iterates over the events. Each iteration of the loop is called as Tick in which it tries to execute the events scheduled in the callback queue. These events are nothing but the callbacks functions. Imagine you are fetching a resource over REST API and it is an asynchronous event and when it is complete in due time you would like your function invoked with response of API. This function is nothing but the Callback which gets executed by the event loop when the API is successful.

There are other different queues other than callback queues in the Event loop like Job Queues and there is special way timers(setTimeout) are handled in Event loop.

Hosting Environment and Javascript Engine

Top comments (0)