Last active
August 29, 2015 14:01
-
-
Save wengxt/834b38b8746bcc25ea20 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) { | |
tasks--; | |
async.eachSeries(arr, function(n, cb) { | |
// do stuff here. | |
if (Math.random() > 0.5) { | |
setTimeout(output, 1000, key, n, cb); | |
} else { | |
cb(); | |
} | |
}, function(err) { | |
// operations after array iteration completed. | |
if (tasks === 0) { | |
// All tasks done, return to callback | |
callback(); | |
} | |
}); | |
} | |
} | |
m(obj, done); | |
console.log("Where should this be"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment