1

This question already has an answer here:

Is it possible to run concurrent tasks using web3.js and an Ethereum client?

For example, say we have the following code to iterate through a number of blocks:

var startBlockNumber = 0;
var endBlockNumber = 1000;

for (var i = startBlockNumber; i <= endBlockNumber; i++) {
        var block = web3.eth.getBlock(i, true);
        if (block != null && block.transactions != null) {
          block.transactions.forEach( function(e) {
                do_something(e);
          }})
        }
}

Is it possible to run the do_something() function concurrently so that the code doesn't wait for each transaction to be processed sequentially?

Edit:

I want to process each transaction concurrently in a private block chain using a function which may have a high cost in time.

marked as duplicate by galahad, niksmac, Nicolas Massart, Tjaden Hess, Joris Bontje Jul 22 '16 at 8:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Could you elaborate a bit more of what you're trying to achieve? As per the code, you're trying to run the do_something function n times where n=transactions.length in a block. According to the conditions in your code, this function gets executed only if a block has transactions. – galahad Jul 13 '16 at 14:38
  • I want to run the javascript highlighted above in a browser and execute the function do_something() concurrently on each transaction of each block. – Sebi Jul 13 '16 at 14:44