mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Added a close function to clean up unfired timeouts on a redeploy
This commit is contained in:
parent
c85ab75fe3
commit
670a6cd933
@ -18,6 +18,7 @@
|
||||
|
||||
// Require main module
|
||||
var RED = require("../../red/red");
|
||||
var idList = [];
|
||||
|
||||
// main node definition
|
||||
function PauseNode(n) {
|
||||
@ -28,10 +29,20 @@ function PauseNode(n) {
|
||||
|
||||
this.on("input", function(msg) {
|
||||
var node= this;
|
||||
setTimeout(function(){node.send(msg);}, node.timeout);
|
||||
var id;
|
||||
id = setTimeout(function(){
|
||||
idList.splice(idList.indexOf(id),1);
|
||||
node.send(msg);
|
||||
}, node.timeout);
|
||||
idList.push(id);
|
||||
});
|
||||
}
|
||||
|
||||
// register node
|
||||
RED.nodes.registerType("pause",PauseNode);
|
||||
|
||||
PauseNode.prototype.close = function() {
|
||||
for (var i=0; i<idList.length; i++ ) {
|
||||
clearTimeout(idList[i]);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user