Last active
August 29, 2015 14:01
-
-
Save wengxt/8971e4fbe92fbe74bf70 to your computer and use it in GitHub Desktop.
This file contains 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 = ["a", "b", "c"]; | |
function done() | |
{ | |
console.log("Done"); | |
} | |
function output(key, n, cb) | |
{ | |
console.log(key); | |
console.log(n); | |
cb(); | |
} | |
function m(obj, callback) { | |
var tasks = Object.keys(obj).length; | |
var arr = ['one', 'two', 'three']; | |
for (key in obj) { | |
async.eachSeries(arr, function (key) { | |
return function (n, cb) { | |
// do stuff here. | |
setTimeout(output, 1000, key, n, cb); | |
} | |
}(key), function(err) { | |
tasks--; | |
// operations after array iteration completed. | |
if (tasks === 0) { | |
// All tasks done, return to callback | |
callback(); | |
} | |
}); | |
} | |
} | |
m(obj, done); | |
console.log("This appears first"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment