I'm using async
and trying to get data to pass back. Is this possible or do I need to use another library approach?
Ideally, I'd like to do something like:
async.forEach(txids, processTransaction, function(asyncErr, outputTotal) {
I think you want async.reduce()
, similar to Array.reduce()
but asynchronous.
The given example is:
async.reduce([1,2,3], 0, function(memo, item, callback){
// pointless async:
process.nextTick(function(){
callback(null, memo + item)
});
}, function(err, result){
// result is now equal to the last value of memo, which is 6
});
You would probably do something similar to:
async.reduce(txids, {}, processTransaction, function(err, output) { });
I'm not sure what processTransaction
returns, so I'm not sure what your memo
(or initialValue
) should be.