You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing a native module node-winapi. I'm trying to implement an asynchronous function WaitForProcessToExit(pid), which infinitely waits for a certain process to terminate. I'm using Napi::AsyncWorker.
Everything works as intended, with a caveat: this async call prevents Node.js from exiting. I want Node.js to exit when it has nothing else to do, like it does with child_process.unref(). How do I do that?
The text was updated successfully, but these errors were encountered:
@o2genumNapi::AsyncWorker doesn’t really support this – it’s built more with CPU-bound functions that eventually come to an end in mind.
I’m afraid you might have to use libuv directly here; calling uv_unref() on an uv_async_t would do the same thing as child_process.unref(), and you may have to create a separate thread for calling WaitForProcessToExit() manually. In order to cancel the call when Node.js exits, I think you could then register a N-API cleanup hook that stops the thread manually (which iirc works well for Windows).
I'm writing a native module node-winapi. I'm trying to implement an asynchronous function
WaitForProcessToExit(pid)
, which infinitely waits for a certain process to terminate. I'm usingNapi::AsyncWorker
.Everything works as intended, with a caveat: this async call prevents Node.js from exiting. I want Node.js to exit when it has nothing else to do, like it does with
child_process.unref()
. How do I do that?The text was updated successfully, but these errors were encountered: