Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a list of callbacks in the Node work queue? (or, Why won't Node exit?)

Tags:

node.js

It says on the Node.js about page:

Node exits the event loop when there are no more callbacks to perform.

Is there a way to find out which callbacks are keeping Node from exiting?

like image 946
Dmitry Minkovsky Avatar asked Jul 31 '13 02:07

Dmitry Minkovsky


People also ask

How do I get callbacks in node js?

Once file I/O is complete, it will call the callback function while passing the callback function, the content of the file as a parameter. So there is no blocking or wait for File I/O. This makes Node. js highly scalable, as it can process a high number of requests without waiting for any function to return results.

What is callback queue in node js?

The callback queues are queues that hold callback functions to asynchronous operations when they have been completed in the background. They work in a first-in-first-out (FIFO) manner. We'll look at different types of callback queues later in this article. Note that Node.

How many callbacks can respond to any event in Node js?

EventEmitter.defaultMaxListeners By default, a maximum of 10 listeners can be registered for any single event.

How many callback functions can be executed at any time?

As long as the callback code is purely sync than no two functions can execute parallel.


1 Answers

You can use process._getActiveHandles() and process._getActiveRequests()

See this discussion in node.js mailing list.

update: there is a good package for this - https://github.com/mafintosh/why-is-node-running

like image 194
Andrey Sidorov Avatar answered Sep 22 '22 01:09

Andrey Sidorov