mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #164 from hardillb/master
Fix delay node singleton issues
This commit is contained in:
commit
af50fe876f
@ -16,15 +16,14 @@
|
|||||||
|
|
||||||
//Simple node to introduce a pause into a flow
|
//Simple node to introduce a pause into a flow
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||||
var node;
|
|
||||||
|
|
||||||
function random() {
|
function random(n) {
|
||||||
var wait = node.randomFirst + (node.diff * Math.random());
|
var wait = n.randomFirst + (n.diff * Math.random());
|
||||||
if (node.buffer.length > 0) {
|
if (n.buffer.length > 0) {
|
||||||
node.send(node.buffer.pop());
|
n.send(n.buffer.pop());
|
||||||
node.randomID = setTimeout(random,wait);
|
n.randomID = setTimeout(function() {random(n);},wait);
|
||||||
} else {
|
} else {
|
||||||
node.randomID = -1;
|
n.randomID = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,11 +80,10 @@ function DelayNode(n) {
|
|||||||
this.buffer = [];
|
this.buffer = [];
|
||||||
this.intervalID = -1;
|
this.intervalID = -1;
|
||||||
this.randomID = -1;
|
this.randomID = -1;
|
||||||
node = this;
|
var node = this;
|
||||||
|
|
||||||
if (this.pauseType === "delay") {
|
if (this.pauseType === "delay") {
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
node = this;
|
|
||||||
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);
|
||||||
@ -133,7 +131,7 @@ function DelayNode(n) {
|
|||||||
node.buffer.push(msg);
|
node.buffer.push(msg);
|
||||||
if (node.randomID === -1) {
|
if (node.randomID === -1) {
|
||||||
var wait = node.randomFirst + (node.diff * Math.random());
|
var wait = node.randomFirst + (node.diff * Math.random());
|
||||||
node.randomID = setTimeout(random,wait);
|
node.randomID = setTimeout(function() {random(node);},wait);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user