1
0
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:
Ben Hardill 2013-09-10 23:18:15 +01:00
parent c85ab75fe3
commit 670a6cd933

View File

@ -18,6 +18,7 @@
// Require main module // Require main module
var RED = require("../../red/red"); var RED = require("../../red/red");
var idList = [];
// main node definition // main node definition
function PauseNode(n) { function PauseNode(n) {
@ -28,10 +29,20 @@ function PauseNode(n) {
this.on("input", function(msg) { this.on("input", function(msg) {
var node= this; 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 // register node
RED.nodes.registerType("pause",PauseNode); RED.nodes.registerType("pause",PauseNode);
PauseNode.prototype.close = function() {
for (var i=0; i<idList.length; i++ ) {
clearTimeout(idList[i]);
}
}