add reset feature to batch node

This commit is contained in:
Hiroyasu Nishiyama
2020-05-05 21:07:55 +09:00
parent 417d2cb40a
commit 8750c4b121
4 changed files with 121 additions and 6 deletions

View File

@@ -179,6 +179,11 @@ module.exports = function(RED) {
}
node.pending = [];
this.on("input", function(msg) {
if (msg.hasOwnProperty("reset")) {
node.pending = [];
node.pending_count = 0;
return;
}
var queue = node.pending;
queue.push(msg);
node.pending_count++;
@@ -204,11 +209,19 @@ module.exports = function(RED) {
var interval = Number(n.interval || "0") *1000;
var allow_empty_seq = n.allowEmptySequence;
node.pending = []
var timer = setInterval(function() {
function msgHandler() {
send_interval(node, allow_empty_seq);
node.pending_count = 0;
}, interval);
}
var timer = setInterval(msgHandler, interval);
this.on("input", function(msg) {
if (msg.hasOwnProperty("reset")) {
clearInterval(timer);
node.pending = [];
node.pending_count = 0;
timer = setInterval(msgHandler, interval);
return;
}
node.pending.push(msg);
node.pending_count++;
var max_msgs = max_kept_msgs_count(node);
@@ -230,6 +243,11 @@ module.exports = function(RED) {
});
node.pending = {};
this.on("input", function(msg) {
if (msg.hasOwnProperty("reset")) {
node.pending = {};
node.pending_count = 0;
return;
}
concat_msg(node, msg);
});
this.on("close", function() {

View File

@@ -39,4 +39,5 @@
<p>This node will buffer messages internally in order to work across sequences. The
runtime setting <code>nodeMessageBufferMaxLength</code> can be used to limit how many messages nodes
will buffer.</p>
<p>If a message is received with the <b>msg.reset</b> property set, the buffered messages are deleted and not sent.</p>
</script>

View File

@@ -31,4 +31,6 @@
</dl>
<h4>メッセージの蓄積</h4>
<p>このノードの処理ではメッセージ列の処理のためメッセージを内部に蓄積します<b>settings.js</b><code>nodeMessageBufferMaxLength</code></p>
<p>メッセージが<b>msg.reset</b></p>
</script>