Fix regression in delay node.

topic based queue was emptying all the time instead of spreading out
messages.
This commit is contained in:
Dave Conway-Jones 2016-04-24 11:08:58 +01:00
parent d0f57efe0b
commit 8fc0018cb9
1 changed files with 28 additions and 28 deletions

View File

@ -78,30 +78,30 @@ module.exports = function(RED) {
this.drop = n.drop; this.drop = n.drop;
var node = this; var node = this;
if (this.pauseType === "delay") { if (node.pauseType === "delay") {
this.on("input", function(msg) { node.on("input", function(msg) {
var id; var id;
id = setTimeout(function() { id = setTimeout(function() {
node.idList.splice(node.idList.indexOf(id),1); node.idList.splice(node.idList.indexOf(id),1);
if (node.idList.length === 0) { node.status({}); } if (node.idList.length === 0) { node.status({}); }
node.send(msg); node.send(msg);
}, node.timeout); }, node.timeout);
this.idList.push(id); node.idList.push(id);
if ((node.timeout > 1000) && (node.idList.length !== 0)) { if ((node.timeout > 1000) && (node.idList.length !== 0)) {
node.status({fill:"blue",shape:"dot",text:" "}); node.status({fill:"blue",shape:"dot",text:" "});
} }
}); });
this.on("close", function() { node.on("close", function() {
for (var i=0; i<this.idList.length; i++ ) { for (var i=0; i<node.idList.length; i++ ) {
clearTimeout(this.idList[i]); clearTimeout(node.idList[i]);
} }
this.idList = []; node.idList = [];
this.status({}); node.status({});
}); });
} else if (this.pauseType === "rate") { } else if (node.pauseType === "rate") {
this.on("input", function(msg) { node.on("input", function(msg) {
if (!node.drop) { if (!node.drop) {
if ( node.intervalID !== -1) { if ( node.intervalID !== -1) {
node.buffer.push(msg); node.buffer.push(msg);
@ -109,7 +109,7 @@ module.exports = function(RED) {
node.status({text:node.buffer.length}); node.status({text:node.buffer.length});
} }
if (node.buffer.length > 1000) { if (node.buffer.length > 1000) {
node.warn(this.name + " " + RED._("delay.error.buffer")); node.warn(node.name + " " + RED._("delay.error.buffer"));
} }
} else { } else {
node.send(msg); node.send(msg);
@ -141,15 +141,15 @@ module.exports = function(RED) {
} }
}); });
this.on("close", function() { node.on("close", function() {
clearInterval(this.intervalID); clearInterval(node.intervalID);
this.buffer = []; node.buffer = [];
node.status({}); node.status({});
}); });
} else if ((this.pauseType === "queue") || (this.pauseType === "timed")) { } else if ((node.pauseType === "queue") || (node.pauseType === "timed")) {
this.intervalID = setInterval(function() { node.intervalID = setInterval(function() {
if (this.pauseType === "queue") { if (node.pauseType === "queue") {
if (node.buffer.length > 0) { if (node.buffer.length > 0) {
node.send(node.buffer.shift()); // send the first on the queue node.send(node.buffer.shift()); // send the first on the queue
} }
@ -162,7 +162,7 @@ module.exports = function(RED) {
node.status({text:node.buffer.length}); node.status({text:node.buffer.length});
},node.rate); },node.rate);
this.on("input", function(msg) { node.on("input", function(msg) {
if (!msg.hasOwnProperty("topic")) { msg.topic = "_none_"; } if (!msg.hasOwnProperty("topic")) { msg.topic = "_none_"; }
var hit = false; var hit = false;
for (var b in node.buffer) { // check if already in queue for (var b in node.buffer) { // check if already in queue
@ -175,27 +175,27 @@ module.exports = function(RED) {
node.status({text:node.buffer.length}); node.status({text:node.buffer.length});
}); });
this.on("close", function() { node.on("close", function() {
clearInterval(this.intervalID); clearInterval(node.intervalID);
this.buffer = []; node.buffer = [];
node.status({}); node.status({});
}); });
} else if (this.pauseType === "random") { } else if (node.pauseType === "random") {
this.on("input", function(msg) { node.on("input", function(msg) {
var wait = node.randomFirst + (node.diff * Math.random()); var wait = node.randomFirst + (node.diff * Math.random());
var id = setTimeout(function() { var id = setTimeout(function() {
node.idList.splice(node.idList.indexOf(id),1); node.idList.splice(node.idList.indexOf(id),1);
node.send(msg); node.send(msg);
}, wait); }, wait);
this.idList.push(id); node.idList.push(id);
}); });
this.on("close", function() { node.on("close", function() {
for (var i=0; i<this.idList.length; i++ ) { for (var i=0; i<node.idList.length; i++ ) {
clearTimeout(this.idList[i]); clearTimeout(node.idList[i]);
} }
this.idList = []; node.idList = [];
}); });
} }