Handle errors thrown in Function node setTimeout/Interval

This commit is contained in:
Nick O'Leary 2015-11-15 22:22:17 +00:00
parent 1d9d5c6bc7
commit 35e2caff13
1 changed files with 22 additions and 6 deletions

View File

@ -92,11 +92,18 @@ module.exports = function(RED) {
context: { context: {
global:RED.settings.functionGlobalContext || {} global:RED.settings.functionGlobalContext || {}
}, },
setTimeout: function (func,delay) { setTimeout: function () {
var timerId = setTimeout(function() { var func = arguments[0];
var timerId;
arguments[0] = function() {
sandbox.clearTimeout(timerId); sandbox.clearTimeout(timerId);
func(); try {
},delay); func.apply(this,arguments);
} catch(err) {
node.error(err,{});
}
};
timerId = setTimeout.apply(this,arguments);
node.outstandingTimers.push(timerId); node.outstandingTimers.push(timerId);
return timerId; return timerId;
}, },
@ -107,8 +114,17 @@ module.exports = function(RED) {
node.outstandingTimers.splice(index,1); node.outstandingTimers.splice(index,1);
} }
}, },
setInterval: function(func,delay) { setInterval: function() {
var timerId = setInterval(func,delay); var func = arguments[0];
var timerId;
arguments[0] = function() {
try {
func.apply(this,arguments);
} catch(err) {
node.error(err,{});
}
};
timerId = setInterval.apply(this,arguments);
node.outstandingIntervals.push(timerId); node.outstandingIntervals.push(timerId);
return timerId; return timerId;
}, },