From 3e82d5aad5ee58e2ce128e7bd016850746c519db Mon Sep 17 00:00:00 2001 From: cubedro Date: Tue, 2 Jun 2015 00:49:25 +0300 Subject: [PATCH] added chain filter dobounce --- lib/node.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/node.js b/lib/node.js index fd5857a..b409dd3 100644 --- a/lib/node.js +++ b/lib/node.js @@ -105,6 +105,7 @@ function Node () this._socket = false; this._latestQueue = null; + this._chainDebouncer = 0; this.pendingFilter = false; this.chainFilter = false; this.updateInterval = false; @@ -666,7 +667,24 @@ Node.prototype.setWatches = function() console.info('>>>', 'Chain Filter triggered: ', chalk.reset.red(hash), '- last trigger:', chalk.reset.cyan(time)); - self._latestQueue.push(hash); + if(time < 5) + { + this._chainDebouncer++; + } else { + this._chainDebouncer = 0; + } + + if(this._chainDebouncer < 20) + { + self._latestQueue.push(hash); + } + else + { + debounce(function() { + self._latestQueue.push(hash); + self._chainDebouncer = 0; + }, 5); + } }); console.success("Installed chain filter");