In my application development, I am using
setInterval(function() {
// some code
// runs here
}, 60000);
I want to execute some code on 1 minute interval and my code may take 2-3 minutes in some cases.
<execute code> - <wait 1 minute> - <execute code> - <wait 1 minute> ......so on
I tried with setInterval function but noticed that setInterval does not wait for inner code to complete. Please suggest how can i achieve this in javascript.
Thanks
setTimeoutmight be a better option so you not start the next iteration before the first has completed.setInteverlorsetTimeoutbecuase your users will lose interest and move on to different tabs and that will heavily deprioritize your tab and cause your interval basically be completely invalidated. What do you actually want to do? I.e. the interval is a means to an end, what actually happens once a minute? Is the one minute mark important? Because it probably isn't: what should your user(s) see when they come back to your tab?