Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion throttle.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@
For example: setting the node to <code>10 seconds</code> means, that only one message in ten seconds will be forwarded.</p>
<p><strong>By Count:</strong><br/>
Limits the passed through messages by a given count.
The counter will be reset when a message with <code>msg.reset</code> was received.
For example: setting the node to a count of <code>5</code> means, that only every fifth message will be forwarded.</p>
<p><strong>By Block Size:</strong><br/>
Limits the passed through messages by a given block size.
The counter will be reset when a message with <code>msg.reset</code> was received.
For example: setting the node to a block size of <code>5</code> means, that only the first five messages will be forwarded.</p>
<p><strong>By Reset:</strong><br/>
Will only pass through a single message, when a message with <code>msg.reset</code> was received before.</p>
Will only pass through a single message, when a message with <code>msg.reset</code> was received before. Consecutive <code>msg.reset</code> messages will be treated as one.</p>
<p>Every other messages will be dropped!</p>
</script>

Expand Down
22 changes: 15 additions & 7 deletions throttle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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
Expand Down