Skip to content

Instantly share code, notes, and snippets.

@lvivski
Forked from WebReflection/Queue.js
Created June 1, 2012 17:02
Show Gist options
  • Save lvivski/2853647 to your computer and use it in GitHub Desktop.
Save lvivski/2853647 to your computer and use it in GitHub Desktop.
All you need to manage queues
function Queue(q) {"use strict";
// (C) WebReflection - Mit Style License
var
next = function next() {
return (callback = q.shift()) ? !!callback(q) || !0 : !1;
},
callback
;
(q.wait = function wait(condition, delay) {
condition || callback && q.unshift(callback);
setTimeout(q.next = next, delay || 0);
})(1);
return q;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment