Skip to content

Instantly share code, notes, and snippets.

@jasonbyrne
Created October 30, 2015 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonbyrne/5924599eb2ede2262243 to your computer and use it in GitHub Desktop.
Save jasonbyrne/5924599eb2ede2262243 to your computer and use it in GitHub Desktop.
Untested queue
var q = (function() {
var me = this,
_callbacks = [],
_index = -1,
_nonePending = true;
me.then = function(callback) {
// Add this to the queue
_callbacks.push(callback);
};
me.next = function() {
// See if there is another one to execute
if (_index < _callbacks.length) {
// Increment index
_index++;
_nonePending = false;
_callbacks[_index](me);
}
else {
_nonePending = true;
}
};
me.start = function() {
if (_nonePending) {
me.next();
}
};
return me;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment