Skip to content

Instantly share code, notes, and snippets.

@dgershman
Created January 10, 2013 22:14
Show Gist options
  • Save dgershman/4506266 to your computer and use it in GitHub Desktop.
Save dgershman/4506266 to your computer and use it in GitHub Desktop.
async example forEach
var async = require('async');
var obj = [ "apple", "banana", "orange", "pineapple", "kiwi", "watermelon", "grape" ];
function getObj(i, callback) {
setTimeout(function() {
console.log(i)
callback(null);
}, 2000);
}
/*for (var i = 0; i < obj.length; i++) {
getObj(i, function(data) {
console.log(data);
});
}*/
async.forEach(obj, getObj, function(err) {
console.log("done");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment