I have a recursive polling function that does some stuff and then calls itself with a setTimeout of 100 ms. However, if I call another synchronous function that does some stuff for a long time while the recursive polling function is running, I assume the function called with a setTimeout of 100ms will be queued, but if that long function does not return within a specified amount of time, will the browser simply discard the queued function? I’m asking this because it seems that the recursive polling function stops running after this other long running function is called. Also I checked with console.log‘s that the recursive function reaches and calls the setTimeout but the function passed to setTimeout never is called after the long synchronous function is called. This is all in Chrome 23 and Firefox 15.
I have a recursive polling function that does some stuff and then calls itself
Share
setTimeoutfunctions cannot be “automatically” cancelled – so long as you allow the browser to return to its event loop they will get called.Should you want to have a timer function that cancels itself automatically that should be relatively easy to achieve:
i.e. call
fafter timet0, but only if timet1hasn’t passed.