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

Update delay node status without spawning unecessary intervals

This commit is contained in:
Nick O'Leary 2017-07-03 21:23:14 +01:00
parent b8c80a2310
commit 18615640e0
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -122,28 +122,38 @@ module.exports = function(RED) {
} }
else if (node.pauseType === "rate") { else if (node.pauseType === "rate") {
var olddepth = 0; var olddepth = 0;
node.busy = setInterval(function() { node.reportDepth = function() {
if (node.buffer.length > 0) { if (!node.busy) {
node.status({text:node.buffer.length}); node.busy = setTimeout(function() {
if (node.buffer.length > 0) {
node.status({text:node.buffer.length});
} else {
node.status({});
}
node.busy = null;
},500);
} }
},333); }
node.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);
node.reportDepth();
} }
else { else {
node.send(msg); node.send(msg);
node.reportDepth();
node.intervalID = setInterval(function() { node.intervalID = setInterval(function() {
if (node.buffer.length === 0) { if (node.buffer.length === 0) {
clearInterval(node.intervalID); clearInterval(node.intervalID);
node.intervalID = -1; node.intervalID = -1;
node.status({});
olddepth = 0; olddepth = 0;
} }
if (node.buffer.length > 0) { if (node.buffer.length > 0) {
node.send(node.buffer.shift()); node.send(node.buffer.shift());
} }
node.reportDepth();
},node.rate); },node.rate);
} }
} }
@ -169,7 +179,7 @@ module.exports = function(RED) {
}); });
node.on("close", function() { node.on("close", function() {
clearInterval(node.intervalID); clearInterval(node.intervalID);
clearInterval(node.busy); clearTimeout(node.busy);
node.buffer = []; node.buffer = [];
node.status({}); node.status({});
}); });