Skip to content

Instantly share code, notes, and snippets.

@ljharb
Forked from WebReflection/Queue.js
Last active December 12, 2015 05:58
Show Gist options
  • Save ljharb/4725444 to your computer and use it in GitHub Desktop.
Save ljharb/4725444 to your computer and use it in GitHub Desktop.
/*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