Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Timer.unref() #6644

Closed
liveinjs opened this issue Dec 6, 2013 · 10 comments
Closed

Timer.unref() #6644

liveinjs opened this issue Dec 6, 2013 · 10 comments

Comments

@liveinjs
Copy link

liveinjs commented Dec 6, 2013

var t = setTimeout(function(){console.log("t")}, 10);
t.unref();

and

 var t = setTimeout(function(){console.log("t")}, 1000);
t.unref();

These two code snippets to be run ,but the result is different .

@othiym23
Copy link

othiym23 commented Dec 6, 2013

This is to be expected. When you unref the timer in the first case, because the timeout is so short the timer has a chance to run before the process exits. In the second, the timer is set to fire too far in the future and libuv exits the event loop (and the process) before t can be printed to the console. This is why timers aren't unreferenced by default.

@tjfontaine
Copy link

thanks for clarifying @othiym23 I was confused by what I was supposed to be seeing here.

So while he's right it's not entirely surprising, I am slightly bemused by the fact that it's happening and I want to look at the event loop more closely to see how this happens more precisely

@liveinjs
Copy link
Author

liveinjs commented Dec 6, 2013

@othiym23 @tjfontaine ,,

so,if

var delay = somefunction(){return somenumber };
var t2 = set Timeout(function(){ console.log("t2")}, delay);

the result is Uncertain ....

@tjfontaine
Copy link

Unref'ing a handle in general will result in less than predictable
scenarios if you're unaware of what else is holding the loop open. But
then again you're explicitly waking the event loop to not care about
that handle

@tjfontaine
Copy link

*asking not waking ... stupid autocorrect

@liveinjs
Copy link
Author

liveinjs commented Dec 6, 2013

thank you @tjfontaine

@trevnorris
Copy link

Think this is non-issue. Ping if this isn't the case.

@tjfontaine
Copy link

actually I still want to investigate this.

@tjfontaine tjfontaine reopened this Dec 7, 2013
@ghost ghost assigned tjfontaine Dec 7, 2013
@jasnell
Copy link
Member

jasnell commented May 28, 2015

@tjfontaine ... were there any followups on this?

@jasnell
Copy link
Member

jasnell commented Jun 3, 2015

Closing due to lack of activity

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants