Skip to content

Instantly share code, notes, and snippets.

@cvazac
Last active September 14, 2016 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvazac/7d552786462ccab9b0aebb069866edad to your computer and use it in GitHub Desktop.
Save cvazac/7d552786462ccab9b0aebb069866edad to your computer and use it in GitHub Desktop.
(function() {
var tasks = []
function run() {
tasks.push(Array.prototype.slice.call(arguments))
waitThenRun()
}
function waitThenRun() {
requestAnimationFrame(function() {
if (tasks.length === 0) {
return
}
var task = tasks.shift()
var method = task.shift()
var context = task.shift()
method.apply(context, task)
waitThenRun()
})
}
window.TaskQueue = {
run: run
}
})()
/*
Usage:
TaskQueue.run(
function (a, b, c) {
console.info(a, b, c, ' ?== 0 1 2')
}, undefined, 0, 1, 2)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment