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">
|
<div id="rate-details" class="form-row">
|
||||||
<label for="node-input-rate"><i class="icon-time"></i> To</label>
|
<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">
|
<input type="text" id="node-input-rate" placeholder="1" style="direction:rtl; width:30px !important">
|
||||||
<label for="node-input-reateUnits">message(s) per</label>
|
<label for="node-input-reateUnits">msg(s) per</label>
|
||||||
<select id="node-input-rateUnits" style="width:140px !important">
|
<select id="node-input-rateUnits" style="width:140px !important">
|
||||||
<option value="second">Second</option>
|
<option value="second">Second</option>
|
||||||
<option value="minute">Minute</option>
|
<option value="minute">Minute</option>
|
||||||
<option value="hour">Hour</option>
|
<option value="hour">Hour</option>
|
||||||
<option value="day">Day</option>
|
<option value="day">Day</option>
|
||||||
</select>
|
</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>
|
||||||
|
|
||||||
<div id="random-details" class="form-row">
|
<div id="random-details" class="form-row">
|
||||||
@ -90,7 +92,8 @@
|
|||||||
rateUnits: {value: "second"},
|
rateUnits: {value: "second"},
|
||||||
randomFirst: {value:"1", required:true, validate:RED.validators.number()},
|
randomFirst: {value:"1", required:true, validate:RED.validators.number()},
|
||||||
randomLast: {value:"5", 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
|
inputs:1, // set the number of inputs - only 0 or 1
|
||||||
outputs:1, // set the number of outputs - 0 to n
|
outputs:1, // set the number of outputs - 0 to n
|
||||||
|
@ -80,6 +80,7 @@ function DelayNode(n) {
|
|||||||
this.buffer = [];
|
this.buffer = [];
|
||||||
this.intervalID = -1;
|
this.intervalID = -1;
|
||||||
this.randomID = -1;
|
this.randomID = -1;
|
||||||
|
this.lastSent = Date.now();
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
if (this.pauseType === "delay") {
|
if (this.pauseType === "delay") {
|
||||||
@ -101,23 +102,31 @@ function DelayNode(n) {
|
|||||||
|
|
||||||
} else if (this.pauseType === "rate") {
|
} else if (this.pauseType === "rate") {
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
if ( node.intervalID !== -1) {
|
if (node.drop) {
|
||||||
node.buffer.push(msg);
|
if ( node.intervalID !== -1) {
|
||||||
if (node.buffer.length > 1000) {
|
node.buffer.push(msg);
|
||||||
node.warn(this.name + " buffer exceeded 1000 messages");
|
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 {
|
} else {
|
||||||
node.send(msg);
|
var now = Date.now();
|
||||||
node.intervalID = setInterval(function() {
|
if (now-node.lastSent > node.rate) {
|
||||||
if (node.buffer.length === 0) {
|
node.lastSent = now;
|
||||||
clearInterval(node.intervalID);
|
node.send(msg);
|
||||||
node.intervalID = -1;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (node.buffer.length > 0) {
|
|
||||||
node.send(node.buffer.shift());
|
|
||||||
}
|
|
||||||
},node.rate);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user