teh_senaus
teh_senaus

Reputation: 1444

What's stopping my command from terminating?

I'm writing a command line tool for installing Windows services using Node JS. After running a bunch of async operations, my tool should print a success message then quit. Sometimes however, it prints its success message and doesn't quit.

Is there a way to view what is queued on Node's internal event loop, so I can see what is preventing my tool from quitting?

Upvotes: 3

Views: 176

Answers (2)

jmar777
jmar777

Reputation: 39679

The most typical culprit for me in CLI apps is event listeners that are keeping the process alive. I obviously can't say if that's relevant to you without seeing your code, though.

To answer your more general question, I don't believe there are any direct ways to view all outstanding tasks in the event loop (at least not from JS-land). You can, however, get pretty close with process._getActiveHandles() and process._getActiveRequests().

I really recommend you look up the documentation for them, though. Because you won't find any. They're undocumented. And they start with underscores. Use at your own peril. :)

Upvotes: 4

vodolaz095
vodolaz095

Reputation: 6986

try to use some tools to clarify the workflow - for example, the https://github.com/caolan/async#waterfall or https://github.com/caolan/async#eachseriesarr-iterator-callback

so, you don't lose the callback called and can catch any erros thrown while executing commands.

I think you also need to provide some code samples that leads to this errors.

Upvotes: 1

Related Questions