Skip to content

Instantly share code, notes, and snippets.

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