Yes.
$ node
> setInterval(function(){console.log("pong")},1000)
{ repeat: 1, callback: [Function] }
> pong
pong
pong
pong
pong
pong
That's not quite the same thing, though. If you do a setTimeout, and
call another setTimeout from within the callback, you have to account
for the time it takes to execute the code up to the second invocation of
setTimeout. e.g.:
function func() {
// Simulating code that takes 200ms to execute:
setTimeout(function() {
console.log('Done');
setTimeout(func, 5000);
}, 200);
}
setTimeout(func, 5000);
This code is executed approximately every 5200ms after the first 5000ms
(unless I have a bug in there), because whatever the callback itself
takes 200ms to execute. Of course, you can imagine what happens if the
200ms is some random time frame.
> setInterval(x, 5000). But I don't see it getting re-executed. I did some
> Googling and I can't find anything that says not to use setInterval.
I don't see why x would not execute repeatedly unless x has a bug in it.
In the app I'm working on, I actually use it to start a background
process that keeps on troughout the uptime of the app.
--
Branko Vukelic
bra...@brankovukelic.com
bra...@herdhound.com
IDEA MACHINE
www.brankovukelic.com
Lead Developer
Herd Hound (tm) - Travel that doesn't bite
www.herdhound.com
Love coffee? You might love Loveffee, too.
loveffee.appspot.com
Thx for the help.
W
Sent from my iPhone
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en