diff --git a/throttle.html b/throttle.html
index 39ea868..8ef33f7 100644
--- a/throttle.html
+++ b/throttle.html
@@ -40,13 +40,14 @@
For example: setting the node to 10 seconds means, that only one message in ten seconds will be forwarded.
By Count:
Limits the passed through messages by a given count.
+ The counter will be reset when a message with msg.reset was received.
For example: setting the node to a count of 5 means, that only every fifth message will be forwarded.
By Block Size:
Limits the passed through messages by a given block size.
The counter will be reset when a message with msg.reset was received.
For example: setting the node to a block size of 5 means, that only the first five messages will be forwarded.
By Reset:
- Will only pass through a single message, when a message with msg.reset was received before.
msg.reset was received before. Consecutive msg.reset messages will be treated as one.
Every other messages will be dropped!
diff --git a/throttle.js b/throttle.js index 6755323..1f7c554 100644 --- a/throttle.js +++ b/throttle.js @@ -52,6 +52,11 @@ module.exports = function(RED) { return this.error("count limit is not numeric", msg); } + if (msg.reset) { + node.count = 0; + return; + } + ++node.count; if( node.count >= node.countLimit ) { @@ -69,25 +74,28 @@ module.exports = function(RED) { return this.error("block size is not numeric", msg); } + if (msg.reset) { + node.block = 0; + return; + } + ++node.block; if( node.block <= node.blockSize ) { node.send(msg); } - else if( msg.reset ) { - node.block = 0; - } } // throttle by reset - else if( node.throttleType === "reset" ) { + else if (node.throttleType === "reset") { + if (msg.reset) { + node.reset = false; + return; + } if( !node.reset ) { node.reset = true; node.send(msg); } - else if( msg.reset ) { - node.reset = false; - } } // unknown throttle type