Possible Solution using a new feature that was implemented as process.watchers()
, but I don't know whether it was included in a released version yet. The pull request is still open as of this post.
But generally speaking, you would write a custom setTimeout
function that add all timeouts to a counter, and right before the timeouts to the callback, it would remove from the counter.
Then create an ongoing interval, and the interval would check and notice when all the walkers are just timeouts set by your custom function.
When it notices this, it would (clear all of its those timeouts, causing an) exit.
This of course is not great, because
- The concept is not proven. (I do not know what kind of data will be returned by
process.watchers()
, or if it even works yet)
- The interval is a polling method. (not nice if you want immediate return at the same time as low CPU usage)