Created
November 17, 2014 14:33
-
-
Save toddself/fdf89f9ece131df0e25d to your computer and use it in GitHub Desktop.
dumb queue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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