I
inetquestion
How do you enable javascript to execute a given function every X
seconds, which is not dependant on any user input?
-Inet
seconds, which is not dependant on any user input?
-Inet
setInterval(yourfunction,milliseconds);
I prefer to use setTimeout so that there is a specified period of time
between the end of the function's execution and the beginning of its
next execution.
function foo() {
// do stuff
// ...
// make a delayed recursive call to foo
setTimeout(foo, 3000);
}
Peter said:Please quote the message to which you are replying or state enough so
your message is sufficient to explain the context of your response.
----
Using setInterval to execute a given function every x seconds can be
dangerous. If the function's execution takes longer than x seconds
than the executions of the function "stack up" and dominate the system
because they are always executing.
I prefer to use setTimeout so that there is a specified period of time
between the end of the function's execution and the beginning of its
next execution.
function foo() {
// do stuff
// ...
// make a delayed recursive call to foo
setTimeout(foo, 3000);
}
Peter
Peter Michaux wrote:
A tiny point of order / question: the call to setTimeout
isn't actually recursive here, is it?
No it is not.
If we are nit picking, foo is defined in terms of itself so it is a
recursively defined function. It does not evolve a recursive process,
however, as the return path is not growing with each call to foo in
the cycle.
Peter said:If we are nit picking, foo is defined in terms of itself so it is a
recursively defined function.
Nonsense.
It does not evolve a recursive process, however, as the return path is
not growing with each call to foo in the cycle.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.