Fix delay to not pass through .reset and .flush props consistently

to close #2349
(it used to not pass them through but did on initial message... now it doesn't)
This commit is contained in:
Dave Conway-Jones 2019-10-25 16:48:35 +01:00
parent e8ef476a6d
commit a96d5096fe
No known key found for this signature in database
GPG Key ID: 302A6725C594817F
1 changed files with 21 additions and 16 deletions

View File

@ -153,15 +153,26 @@ module.exports = function(RED) {
}
else if (node.pauseType === "rate") {
node.on("input", function(msg) {
if (msg.hasOwnProperty("reset")) {
if (node.intervalID !== -1 ) {
clearInterval(node.intervalID);
node.intervalID = -1;
}
node.buffer = [];
node.status({text:"reset"});
return;
}
if (!node.drop) {
var m = RED.util.cloneMessage(msg);
delete m.flush;
if (node.intervalID !== -1) {
if (!msg.hasOwnProperty("flush")) {
node.buffer.push(msg);
//if (!msg.hasOwnProperty("flush")) {
node.buffer.push(m);
node.reportDepth();
}
//}
}
else {
node.send(msg);
node.send(m);
node.reportDepth();
node.intervalID = setInterval(function() {
if (node.buffer.length === 0) {
@ -174,6 +185,12 @@ module.exports = function(RED) {
node.reportDepth();
}, node.rate);
}
if (msg.hasOwnProperty("flush")) {
while (node.buffer.length > 0) {
node.send(node.buffer.shift());
}
node.status({});
}
}
else {
var timeSinceLast;
@ -189,18 +206,6 @@ module.exports = function(RED) {
node.send(msg);
}
}
if (msg.hasOwnProperty("reset")) {
clearInterval(node.intervalID);
node.intervalID = -1;
node.buffer = [];
node.status({text:"reset"});
}
if (msg.hasOwnProperty("flush")) {
while (node.buffer.length > 0) {
node.send(node.buffer.shift());
}
node.status({});
}
});
node.on("close", function() {
clearInterval(node.intervalID);