The browser has some options (provided that the client side is associated with the jquery tag)
First, you can use setImmediate:
https://developer.mozilla.org/en-US/docs/Web/API/window.setImmediate
Secondly, you can use timers and split it, a very simplified example, and then if you want to process more things, just insert them into the subject material from time to time. Any of several permutations on this.
int howoftentocheck = 60*1000; //60s var thingstodoarray = []; thingstodoarray.push("do this"); function checkForStuffToDo(){ if(thingstodoarray.length){ //.. do things be sure and pop or shift the thing you did. }else{ setTimeout(function() { checkForStuffToDo() }, howoftentocheck) } }();
Thirdly, you can use events instead of polling, so register events using, say, jQuery or another library that offers events, then you can fire them when you want to do some processing using .on and .trigger, for example.
http://api.jquery.com/trigger/
I am sure there are several other options, but the goal is to keep the event loop tight so that you are not distracted from the user experience, etc.
source share