When does the node.js event loop end?

I am wondering what are the conditions under which node.js completes the event loop. How does node.js figure out that further events will not be triggered? E.g. in the case of an http client or file reader application.

+4
source share
1 answer

I would recommend you watch this great Philip Roberts video : What the hell is the event loop anyway? | JSConf EU 2014

To explain briefly, Javascript runtime can do one at a time, which is why it is called "single-threaded." However, you have a reason why we can do something at the same time, for example, HTTP requests, etc., because it calls the video as a “browser API” for the browser and for the backend environment such as Node .js, these are C ++ APIs. Now, any of these "external" API calls, such as the HTTP client call, are transferred to the task queue. The event loop has one very simple job. It will always perform one task from the task queue, given that the main column is empty and push it onto the run / execute stack. Thus, the event loop will stop if there are no tasks in the queue (external API calls)

I recommend watching the full video for a better understanding :)

-2
source

All Articles