-
-
Save mattneary/4323637 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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