setInterval with 0 milliseconds, like so:
Obviously, this does not seem like a good idea to me. Can anyone tell me what will be the behaviour of
setInterval here? ("myFunction" makes an AJAX call to the server)
I am asking this because I am having an irregular behaviour in my application. 90% of the times, the application behaves correctly and exactly one call to the server is made. However sometimes, multiple calls are made to the server (until now, maximum is 48 calls) and I am almost certain it is the fault of this line of code.
Browser set a minimal value for the interval. Usualy 10ms, but it can depend on the browser. This means repeat this as fast as I'm possibly allowed. The W3C spec say 4ms : http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#timers
This is correct but probably reveal a design error.
setInterval(myFunction, 0) calls
myFunction continuously with minimum delay. It is almost like calling
myFunction in a infinite loop. Except that here you can stop the loop using the
To have it executed only once with minor delay, use
As you're using AJAX, you don't have to use any timers at all - just call the next AJAX request in the Callback (complete/success event) of the current AJAX request.
Post your current code and we might be able to guide you further.
I assume that in
myFunction() there is a
clearInterval part before the next iteration of the interval, then it will be fine. Otherwise, it will happen again and again.
©2020 All rights reserved.