Reputation: 51
function start() {
// code goes here
setInterval(start, 1800000);
}
start();
as opposed to:
setInterval(start, 1800000);
I want to run start() immediately after I start my node.js server rather than wait 1800000 milliseconds.
Since I am repeatedly calling the setInterval function, do I have to clear it with clearInterval? How would I do so if that were the case?
Upvotes: 0
Views: 95
Reputation: 68393
Since I am repeatedly calling the setInterval function, do I have to clear it with clearInterval?
You are basically creating a new timer every time start
method is invoked, just replace setInterval
with setTimeout
since you are invoking start
method again anyways which will create a new timer on every invocation.
function start() {
// code goes here
setTimeout(start, 1800000);
}
start();
Upvotes: 1