Skip to content

Instantly share code, notes, and snippets.

@flipjs
Created August 6, 2014 22:36
Show Gist options
  • Save flipjs/8ee949beb2cd6f3aac8f to your computer and use it in GitHub Desktop.
Save flipjs/8ee949beb2cd6f3aac8f to your computer and use it in GitHub Desktop.
Async Iterator Snippet
var arr = [1, 2, 3, 4, 5, 6, 7]
, results = []
, len = arr.length
;(function iterator(i) {
if (i >= len) {
callback(null, results)
} else {
async_work(function(err, res) {
if (err) {
callback(err)
} else {
results.push(res)
iterator(i + 1)
}
})
}
})(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment