-
-
Save ljharb/4725444 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
/*global setTimeout */ | |
var Queue = function Queue(q) { | |
"use strict"; | |
// (C) WebReflection - Mit Style License | |
var callback, | |
next = function next() { | |
callback = q.shift(); | |
if (callback) { callback(q); } | |
return !!callback; | |
}; | |
q.wait = function wait(condition, delay) { | |
if (condition || callback) { q.unshift(callback); } | |
q.next = next; | |
setTimeout(next, delay || 0); | |
}; | |
q.wait(1); | |
return q; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment