mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix random delay mode to be random delay not random rate-limited stack.
Documentation says "Introduces a delay into a flow or rate limits messages." but this node was doing delay and rate limit in random mode which doesn't seem that useful. Worse it was a stack not a queue. I can't think of any sane use cases for that behaviour.
This commit is contained in:
parent
7909ca24d3
commit
5510dffe18
@ -21,16 +21,6 @@ module.exports = function(RED) {
|
|||||||
var MILLIS_TO_NANOS = 1000000;
|
var MILLIS_TO_NANOS = 1000000;
|
||||||
var SECONDS_TO_NANOS = 1000000000;
|
var SECONDS_TO_NANOS = 1000000000;
|
||||||
|
|
||||||
function random(n) {
|
|
||||||
var wait = n.randomFirst + (n.diff * Math.random());
|
|
||||||
if (n.buffer.length > 0) {
|
|
||||||
n.send(n.buffer.pop());
|
|
||||||
n.randomID = setTimeout(function() {random(n);},wait);
|
|
||||||
} else {
|
|
||||||
n.randomID = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function DelayNode(n) {
|
function DelayNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
|
||||||
@ -181,18 +171,21 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
} else if (this.pauseType === "random") {
|
} else if (this.pauseType === "random") {
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
node.buffer.push(msg);
|
|
||||||
if (node.randomID === -1) {
|
|
||||||
var wait = node.randomFirst + (node.diff * Math.random());
|
var wait = node.randomFirst + (node.diff * Math.random());
|
||||||
node.randomID = setTimeout(function() {random(node);},wait);
|
var id = setTimeout(function(){
|
||||||
}
|
node.idList.splice(node.idList.indexOf(id),1);
|
||||||
|
node.send(msg);
|
||||||
|
}, wait);
|
||||||
|
this.idList.push(id);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.on("close", function() {
|
this.on("close", function() {
|
||||||
if (this.randomID !== -1) {
|
for (var i=0; i<this.idList.length; i++ ) {
|
||||||
clearTimeout(this.randomID);
|
clearTimeout(this.idList[i]);
|
||||||
}
|
}
|
||||||
|
this.idList = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("delay",DelayNode);
|
RED.nodes.registerType("delay",DelayNode);
|
||||||
|
Loading…
Reference in New Issue
Block a user