I have the following function:
module.exports = {
listAccounts: function (callback) {
var acc = [];
var calls = [];
function processAccounts(account, cb) {
client.getAddressesByAccount(account, function (err, addresses) {
console.log('getting account', account);
acc.push({name: account, addresses: addresses});
return cb();
});
}
client.listAccounts(function (err, res) {
if (err)
return callback(err)
else {
for (var key in res) {
calls.push(
function (cb) {
processAccounts(key, cb);
}
);
}
async.parallel(calls, function (err, results) {
console.log(acc);
})
}
})
}
}
What I want to do is to use the for loop in order to push all the functions to the calls
array and then run async.parallel
to run all the functions.
The problem is, that the calls array looks like this after the for loop finishes:
function (cb) {
processAccounts(key, cb);
},function (cb) {
processAccounts(key, cb);
},function (cb) {
processAccounts(key, cb);
}
It does not translate the key
to the actual value but keeps it as key