var timer = { timerId : 0, timers : [], add : function(fn){ this.timers.push(fn); }, start : function(){ if(this.timerId){ return; } (function runNext(){ if(timer.timers.length > 0){ for(var i = 0; i < timer.timers.length; i++){ if(timer.timers[i]() === false){ timer.timers.splice(i,1); i--; } } timer.timerId = setTimeout(runNext,0); } })(); }, stop : function(){ clearTimeout(this.timerId); this.timerId = 0; }};