1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

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

View File

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