Skip to content

Instantly share code, notes, and snippets.

@ljharb

ljharb/Queue.js

Forked from WebReflection/Queue.js
Last active Dec 12, 2015
Embed
What would you like to do?
/*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