Timer unref ref in nodejs
Timers Unref, Ref in nodejs
If there is no other activity keeping the event loop running, the process may exit before the Timeout object's callback is invoked when Calling timeout.unref()
var timeout = setTimeout(function() {
console.log('setTimeout')
}, 10000);
var interval = setInterval(function(){
console.log("exectute every 10 secs")
}, 5000)
After unref application will stop when other than this setInterval, nothing is running in eventloop
interval.unref();
If I not ref again application will stop because other than this setInterval nothing is running in eventloop
interval.ref();
/**
* References : https://www.bennadel.com/blog/3301-calling-timeout-unref-with-settimeout-does-not-appear-to-be-a-best-practice-in-node-js.htm
* References : https://nodejs.org/api/timers.html
*/
Comments
Post a Comment