Skip to content

Instantly share code, notes, and snippets.

@composite
Created December 13, 2012 06:24
Show Gist options
  • Save composite/4274504 to your computer and use it in GitHub Desktop.
Save composite/4274504 to your computer and use it in GitHub Desktop.
queue function calling continuous, step friendly, without hanging, but less performance for lot of function calls...
function setQueue(func){
setQueue.fns.push(func);
if(!setQueue.isRun){setQueue.isRun=true;setQueue.invoke();}
} setQueue.delay=0;setQueue.fns=[];
setQueue.invoke=function(){
setTimeout(function(){
if(!setQueue.fns.length||!setQueue.isRun){setQueue.isRun=false;return;}
var fn=setQueue.fns.shift();
if(typeof(fn)=='function') fn();
setTimeout(arguments.callee,setQueue.delay);
},setQueue.delay);
};setQueue.pause=function(){setQueue.isRun=false;}
setQueue.clear=function(){setQueue.fns.length=0;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment