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