made history call async

This commit is contained in:
cubedro 2015-05-05 09:24:27 +03:00
parent 592cd23500
commit 66aad76047
1 changed files with 31 additions and 15 deletions

View File

@ -198,12 +198,7 @@ Node.prototype.setupSockets = function()
{
console.info('his', 'Got history request');
var reqHistory = self.getHistory( data );
socket.emit('history', {
id: self.id,
history: reqHistory
});
self.getHistory( data );
})
.on('node-pong', function(data)
{
@ -506,6 +501,8 @@ Node.prototype.getStats = function(forced)
Node.prototype.getHistory = function (range)
{
var self = this;
var history = [];
var interv = {};
@ -519,19 +516,38 @@ Node.prototype.getHistory = function (range)
console.info('his', 'Getting history from', chalk.reset.cyan(interv[0]), 'to', chalk.reset.cyan(interv[interv.length - 1]));
for (var i = 0; i < interv.length; i++)
async.mapSeries(interv, function (number, callback)
{
var block = this.getBlock( interv[i] );
if( block !== null && !_.isUndefined(block.number) )
async.nextTick(function ()
{
history.push( block );
var block;
try {
block = self.formatBlock(web3.eth.getBlock(number, true));
}
catch (err) {
console.error('xx>', 'history block failed: ', err);
callback(err, null);
}
callback(null, block);
});
},
function (err, results)
{
console.timeEnd('=H=', 'his', 'Got history in');
if (err) {
console.error('his', 'history fetch failed:', err);
results = false;
}
}
console.timeEnd('=H=', 'his', 'Got history in');
return history.reverse();
socket.emit('history', {
id: self.id,
history: results.reverse()
});
});
}
Node.prototype.getMinerName = function(miner)