12

Is there a native function that can be executed from Node.js code which outputs an array or an object containing the information about what's currently supposed to be in the Event Loop?

1
  • I'd expect the answer to be "no". Why would you want such a thing? Commented Jun 10, 2015 at 13:06

2 Answers 2

13

Recently there was a request to see what is in the event loop, in io.js project. There were two names of functions surfaced, in this comment,

  1. process._getActiveHandles() gets you handles that are still alive

  2. process._getActiveRequests() gets you info about active libuv requests.

This the most you can collect from the event loop, I guess.

Note: Both of them are undocumented functions and you cannot rely on them in production code.

Sign up to request clarification or add additional context in comments.

Comments

12

You're looking for a uv_loop.

There's a UV_EXTERN void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg); method you can call to iterate the event loop.

Unfortunately, it's not really exposed to JavaScript - so unless you want to do this for fun (and fork node/io.js) then no.

You can wrap calls to the event loop and monitor those but that's slow and not even close - the actual loop isn't in JS land, only small parts of it - and even parts of that (like the microtask queue) are in C++.

A lot of people think of the event loop like an array - it's actually more like:

enter image description here

It's a lot easier to hook on process.nextTick and the timers than on the poll part mentioned above.

2 Comments

What is process.maxDepth ??
@MustafaAgamey we removed that bit maybe 5 years ago IIRC, this answer is 7 and should be read in its spirit of what node does and not as the current state of things

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.