Christopher Allen
Christopher Allen

Reputation: 8599

Timer intterupt Node.JS

I hope this isn't a repeat question, I did my research on the node API documentation pages. I have called a timer into play in one of my scripts.

 setInterval(function,10000);

Now, somewhere down the line, I want the continued execution of the timer to stop.

here is the unref() call I will refer to in a minute

I have seen example scripts where people will format in this sort of way.

var timer = setInterval(function,10000);
....
.... 
// when they want to stop the timer, they run 
timer.unref();

This did not work for me, I received a undefined for the .unref Is this sort of thing impossible? or is there a way for me to stop the timer.

Upvotes: 0

Views: 80

Answers (2)

Vicky Gonsalves
Vicky Gonsalves

Reputation: 11717

You need to use clearInterval

var timer = setInterval(function,10000);
....
.... 
clearInterval(timer);

Upvotes: 1

Buzinas
Buzinas

Reputation: 11735

If using:

var timer = setInterval(function() { }, 10000);

You can use the clearInterval function:

clearInterval(timer);

Upvotes: 3

Related Questions