Created
January 10, 2013 23:17
-
-
Save dgershman/4506647 to your computer and use it in GitHub Desktop.
2nd try at this
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 async = require('async'); | |
| var obj = [ "apple", "banana", "orange", "pineapple", "kiwi", "watermelon", "grape" ]; | |
| function getObj(i, callback) { | |
| setTimeout(function() { | |
| console.log(i) | |
| callback(null); | |
| }, 2000); | |
| } | |
| function getUserData(item, callback) { | |
| setTimeout(function() { | |
| setTimeout(function() { | |
| callback(item); | |
| }, 1000); | |
| }) | |
| } | |
| /*for (var i = 0; i < obj.length; i++) { | |
| getObj(i, function(data) { | |
| console.log(data); | |
| }); | |
| }*/ | |
| /*async.forEach(obj, getObj, function(err) { | |
| console.log("done"); | |
| });*/ | |
| async.forEach(obj, | |
| function(item, callback) { | |
| getUserData(item, function(data) { | |
| console.log(data); | |
| callback(null); | |
| }); | |
| }, | |
| function(err) { | |
| console.log(err + " done"); | |
| } | |
| ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment