mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge pull request #2553 from node-red-hitachi/add-reset-to-batch-node
Add reset feature to batch node
This commit is contained in:
@@ -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,26 @@ 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 = undefined;
|
||||
if (interval > 0) {
|
||||
timer = setInterval(msgHandler, interval);
|
||||
}
|
||||
this.on("input", function(msg) {
|
||||
if (msg.hasOwnProperty("reset")) {
|
||||
if (timer !== undefined) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
node.pending = [];
|
||||
node.pending_count = 0;
|
||||
if (interval > 0) {
|
||||
timer = setInterval(msgHandler, interval);
|
||||
}
|
||||
return;
|
||||
}
|
||||
node.pending.push(msg);
|
||||
node.pending_count++;
|
||||
var max_msgs = max_kept_msgs_count(node);
|
||||
@@ -219,7 +239,9 @@ module.exports = function(RED) {
|
||||
}
|
||||
});
|
||||
this.on("close", function() {
|
||||
clearInterval(timer);
|
||||
if (timer !== undefined) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
node.pending = [];
|
||||
node.pending_count = 0;
|
||||
});
|
||||
@@ -230,6 +252,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() {
|
||||
|
@@ -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>
|
||||
|
@@ -31,4 +31,6 @@
|
||||
</dl>
|
||||
<h4>メッセージの蓄積</h4>
|
||||
<p>このノードの処理ではメッセージ列の処理のためメッセージを内部に蓄積します。<b>settings.js</b>の<code>nodeMessageBufferMaxLength</code>を指定することで蓄積するメッセージの最大値を制限することができます。</p>
|
||||
<p>メッセージが<b>msg.reset</b>プロパティを持つ場合、蓄積したメッセージを削除し送信を行いません。</p>
|
||||
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user