Skip to content

Instantly share code, notes, and snippets.

@mattneary
Forked from anonymous/index.js
Created December 18, 2012 00:08
Show Gist options
  • Save mattneary/4323637 to your computer and use it in GitHub Desktop.
Save mattneary/4323637 to your computer and use it in GitHub Desktop.
var Queue = function(parts) {
var index = 0;
this.read = function() {
var part = parts[index];
index++;
return part;
};
this.next = function() {
var thiz = this;
this.function(this.read(), function() {
// pass in a conditionally recursive callback
thiz.length() && thiz.next();
});
};
this.length = function() {
return parts.length - index;
};
this.push = function(arr) {
[].push.apply(parts, arr);
};
this.go = this.next;
};
// queue up a list for asychronous `mapping`
var queue = new Queue([1,2,3,4,5]);
queue.function = function(part, cb) {
send(part, function() {
// iterate
cb();
});
};
queue.go();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment