mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add drop-intermediate option to Delay rate node
This commit is contained in:
parent
d5b36fcadc
commit
653c02bb15
@ -39,14 +39,16 @@
|
||||
|
||||
<div id="rate-details" class="form-row">
|
||||
<label for="node-input-rate"><i class="icon-time"></i> To</label>
|
||||
<input type="text" id="node-input-rate" placeholder="1" style="direction:rtl; width:50px !important">
|
||||
<label for="node-input-reateUnits">message(s) per</label>
|
||||
<input type="text" id="node-input-rate" placeholder="1" style="direction:rtl; width:30px !important">
|
||||
<label for="node-input-reateUnits">msg(s) per</label>
|
||||
<select id="node-input-rateUnits" style="width:140px !important">
|
||||
<option value="second">Second</option>
|
||||
<option value="minute">Minute</option>
|
||||
<option value="hour">Hour</option>
|
||||
<option value="day">Day</option>
|
||||
</select>
|
||||
<br/>
|
||||
<input style="margin: 20px 0 20px 100px; width: 30px;" type="checkbox" id="node-input-drop"><label style="width: 250px;" for="node-input-drop">drop intermediate messages</label>
|
||||
</div>
|
||||
|
||||
<div id="random-details" class="form-row">
|
||||
@ -90,7 +92,8 @@
|
||||
rateUnits: {value: "second"},
|
||||
randomFirst: {value:"1", required:true, validate:RED.validators.number()},
|
||||
randomLast: {value:"5", required:true, validate:RED.validators.number()},
|
||||
randomUnits: {value: "seconds"}
|
||||
randomUnits: {value: "seconds"},
|
||||
drop: {value:false}
|
||||
},
|
||||
inputs:1, // set the number of inputs - only 0 or 1
|
||||
outputs:1, // set the number of outputs - 0 to n
|
||||
|
@ -80,6 +80,7 @@ function DelayNode(n) {
|
||||
this.buffer = [];
|
||||
this.intervalID = -1;
|
||||
this.randomID = -1;
|
||||
this.lastSent = Date.now();
|
||||
var node = this;
|
||||
|
||||
if (this.pauseType === "delay") {
|
||||
@ -101,23 +102,31 @@ function DelayNode(n) {
|
||||
|
||||
} else if (this.pauseType === "rate") {
|
||||
this.on("input", function(msg) {
|
||||
if ( node.intervalID !== -1) {
|
||||
node.buffer.push(msg);
|
||||
if (node.buffer.length > 1000) {
|
||||
node.warn(this.name + " buffer exceeded 1000 messages");
|
||||
if (node.drop) {
|
||||
if ( node.intervalID !== -1) {
|
||||
node.buffer.push(msg);
|
||||
if (node.buffer.length > 1000) {
|
||||
node.warn(this.name + " buffer exceeded 1000 messages");
|
||||
}
|
||||
} else {
|
||||
node.send(msg);
|
||||
node.intervalID = setInterval(function() {
|
||||
if (node.buffer.length === 0) {
|
||||
clearInterval(node.intervalID);
|
||||
node.intervalID = -1;
|
||||
}
|
||||
|
||||
if (node.buffer.length > 0) {
|
||||
node.send(node.buffer.shift());
|
||||
}
|
||||
},node.rate);
|
||||
}
|
||||
} else {
|
||||
node.send(msg);
|
||||
node.intervalID = setInterval(function() {
|
||||
if (node.buffer.length === 0) {
|
||||
clearInterval(node.intervalID);
|
||||
node.intervalID = -1;
|
||||
}
|
||||
|
||||
if (node.buffer.length > 0) {
|
||||
node.send(node.buffer.shift());
|
||||
}
|
||||
},node.rate);
|
||||
var now = Date.now();
|
||||
if (now-node.lastSent > node.rate) {
|
||||
node.lastSent = now;
|
||||
node.send(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user