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.
do_somethingfunction 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