Skip to content

Instantly share code, notes, and snippets.

@toddself
Created November 17, 2014 14:33
Show Gist options
  • Save toddself/fdf89f9ece131df0e25d to your computer and use it in GitHub Desktop.
Save toddself/fdf89f9ece131df0e25d to your computer and use it in GitHub Desktop.
dumb queue
var queue = [],
running = false;
function addToQueue(job){
queue.push(job);
processJob();
}
function processJob(){
var job;
if(queue.length > 0 && !running){
running = true;
job = queue.shift();
doSomethingAsync(job, function(){
running = false;
processJob();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment