fixed debounce delay

This commit is contained in:
cubedro 2015-04-28 07:05:04 +03:00
parent c8dde06a22
commit ef17dec195

View File

@ -113,6 +113,9 @@ function Node()
this.updateInterval = false; this.updateInterval = false;
this.pingInterval = false; this.pingInterval = false;
this._lastLatestLog = 0;
this._lastPendingLog = 0;
socket.on('open', function open() { socket.on('open', function open() {
socket.emit('hello', { id: self.id, info: self.info, secret: WS_SECRET }); socket.emit('hello', { id: self.id, info: self.info, secret: WS_SECRET });
console.info('The connection has been opened.'); console.info('The connection has been opened.');
@ -487,10 +490,22 @@ Node.prototype.setWatches = function()
this.pendingFilter = web3.eth.filter('pending'); this.pendingFilter = web3.eth.filter('pending');
this.pendingFilter.watch( function(log) { this.pendingFilter.watch( function(log) {
if(PENDING_WORKS) { if(PENDING_WORKS) {
var now = (new Date()).getTime();
var time = now - self._lastPendingLog;
if(time > 50)
{
self.update();
}
else
{
debounce(function() { debounce(function() {
self.updatePending(); self.updatePending();
}, 50); }, 50);
} }
self._lastPendingLog = now;
}
}); });
} }
catch (err) catch (err)
@ -501,10 +516,23 @@ Node.prototype.setWatches = function()
try { try {
this.chainFilter = web3.eth.filter('latest'); this.chainFilter = web3.eth.filter('latest');
this.chainFilter.watch(function(log) { this.chainFilter.watch(function(log)
{
var now = (new Date()).getTime();
var time = now - self._lastLatestLog;
if(time > 50)
{
self.update();
}
else
{
debounce(function() { debounce(function() {
self.update(); self.update();
}, 50); }, 50);
}
self._lastLatestLog = now;
}); });
} }
catch (err) catch (err)