cleanup status on delay node

This commit is contained in:
Dave Conway-Jones 2015-07-08 15:06:46 +01:00
parent 7de3704210
commit d0af4aac4d
1 changed files with 10 additions and 5 deletions

View File

@ -31,7 +31,7 @@ module.exports = function(RED) {
if (n.timeoutUnits === "milliseconds") { if (n.timeoutUnits === "milliseconds") {
this.timeout = n.timeout; this.timeout = n.timeout;
} else if (n.timeoutUnits === "minutes") { } else if (n.timeoutUnits === "minutes") {
this.timeout = n.timeout * (60 * 1000); this.timeout = n.timeout * (60 * 1000);
} else if (n.timeoutUnits === "hours") { } else if (n.timeoutUnits === "hours") {
this.timeout = n.timeout * (60 * 60 * 1000); this.timeout = n.timeout * (60 * 60 * 1000);
@ -81,11 +81,15 @@ module.exports = function(RED) {
if (this.pauseType === "delay") { if (this.pauseType === "delay") {
this.on("input", function(msg) { this.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({}); }
node.send(msg); node.send(msg);
}, node.timeout); }, node.timeout);
this.idList.push(id); this.idList.push(id);
if ((node.timeout > 1000) && (node.idList.length === 0)) {
node.status({fill:"blue",shape:"dot"});
}
}); });
this.on("close", function() { this.on("close", function() {
@ -93,6 +97,7 @@ module.exports = function(RED) {
clearTimeout(this.idList[i]); clearTimeout(this.idList[i]);
} }
this.idList = []; this.idList = [];
this.status({});
}); });
} else if (this.pauseType === "rate") { } else if (this.pauseType === "rate") {
@ -112,7 +117,7 @@ module.exports = function(RED) {
if (node.buffer.length === 0) { if (node.buffer.length === 0) {
clearInterval(node.intervalID); clearInterval(node.intervalID);
node.intervalID = -1; node.intervalID = -1;
node.status({text:""}); node.status({});
} }
if (node.buffer.length > 0) { if (node.buffer.length > 0) {
@ -165,13 +170,13 @@ module.exports = function(RED) {
this.on("close", function() { this.on("close", function() {
clearInterval(this.intervalID); clearInterval(this.intervalID);
this.buffer = []; this.buffer = [];
node.status({text:node.buffer.length}); node.status({});
}); });
} else if (this.pauseType === "random") { } else if (this.pauseType === "random") {
this.on("input", function(msg) { this.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);