0

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) {

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.