Last active
September 14, 2016 22:09
-
-
Save cvazac/7d552786462ccab9b0aebb069866edad to your computer and use it in GitHub Desktop.
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
(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