Skip to content

Instantly share code, notes, and snippets.

@wengxt
Last active August 29, 2015 14:01
Show Gist options
  • Save wengxt/834b38b8746bcc25ea20 to your computer and use it in GitHub Desktop.
Save wengxt/834b38b8746bcc25ea20 to your computer and use it in GitHub Desktop.
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