Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Created June 1, 2012 08:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save WebReflection/2850330 to your computer and use it in GitHub Desktop.
Save WebReflection/2850330 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;
}
@WebReflection
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment