diff --git a/.gitignore b/.gitignore
index d4c991688..6a2ebfaa1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,3 +27,4 @@ docs
.vscode
.nyc_output
sync.ffs_db
+package-lock.json
diff --git a/packages/node_modules/@node-red/nodes/core/function/10-function.html b/packages/node_modules/@node-red/nodes/core/function/10-function.html
index e17f58aca..a29c830f3 100644
--- a/packages/node_modules/@node-red/nodes/core/function/10-function.html
+++ b/packages/node_modules/@node-red/nodes/core/function/10-function.html
@@ -82,6 +82,11 @@
+
+
+
+
+
@@ -353,6 +358,8 @@
return _libs;
}
+
+
RED.nodes.registerType('function',{
color:"#fdd0a2",
category: 'function',
@@ -360,6 +367,7 @@
name: {value:"_DEFAULT_"},
func: {value:"\nreturn msg;"},
outputs: {value:1},
+ timeout:{value:0},
noerr: {value:0,required:true,
validate: function(v, opt) {
if (!v) {
@@ -463,6 +471,25 @@
if (value !== this.value) { $(this).spinner("value", value); }
}
});
+ // 4294967295 is max in node.js timeout.
+ $( "#node-input-timeout" ).spinner({
+ min: 0,
+ max: 4294967294,
+ change: function(event, ui) {
+ var value = this.value;
+ if(value == ""){
+ value = 0;
+ }
+ else
+ {
+ value = parseInt(value);
+ }
+ value = isNaN(value) ? 1 : value;
+ value = Math.max(value, parseInt($(this).attr("aria-valuemin")));
+ value = Math.min(value, parseInt($(this).attr("aria-valuemax")));
+ if (value !== this.value) { $(this).spinner("value", value); }
+ }
+ });
var buildEditor = function(id, stateId, focus, value, defaultValue, extraLibs, offset) {
var editor = RED.editor.createEditor({
@@ -503,7 +530,7 @@
editor:this.editor, // the field name the main text body goes to
mode:"ace/mode/nrjavascript",
fields:[
- 'name', 'outputs',
+ 'name', 'outputs', 'timeout',
{
name: 'initialize',
get: function() {
diff --git a/packages/node_modules/@node-red/nodes/core/function/10-function.js b/packages/node_modules/@node-red/nodes/core/function/10-function.js
index b84ee8571..acb28ecb3 100644
--- a/packages/node_modules/@node-red/nodes/core/function/10-function.js
+++ b/packages/node_modules/@node-red/nodes/core/function/10-function.js
@@ -96,6 +96,14 @@ module.exports = function(RED) {
node.name = n.name;
node.func = n.func;
node.outputs = n.outputs;
+ node.timeout = n.timeout*1;
+ if(node.timeout>0){
+ node.timeoutOptions = {
+ timeout:node.timeout,
+ breakOnSigint:true
+ }
+ }
+
node.ini = n.initialize ? n.initialize.trim() : "";
node.fin = n.finalize ? n.finalize.trim() : "";
node.libs = n.libs || [];
@@ -361,6 +369,10 @@ module.exports = function(RED) {
`+ node.ini +`
})(__initSend__);`;
iniOpt = createVMOpt(node, " setup");
+ if(node.timeout>0){
+ iniOpt.timeout = node.timeout;
+ iniOpt.breakOnSigint = true;
+ }
iniScript = new vm.Script(iniText, iniOpt);
}
node.script = vm.createScript(functionText, createVMOpt(node, ""));
@@ -384,6 +396,11 @@ module.exports = function(RED) {
`+node.fin +`
})();`;
finOpt = createVMOpt(node, " cleanup");
+ if(node.timeout>0){
+ finOpt.timeout = node.timeout;
+ finOpt.breakOnSigint = true;
+ }
+
finScript = new vm.Script(finText, finOpt);
}
var promise = Promise.resolve();
@@ -396,9 +413,12 @@ module.exports = function(RED) {
var start = process.hrtime();
context.msg = msg;
context.__send__ = send;
- context.__done__ = done;
-
- node.script.runInContext(context);
+ context.__done__ = done;
+ var opts = {};
+ if (node.timeout>0){
+ opts = node.timeoutOptions;
+ }
+ node.script.runInContext(context,opts);
context.results.then(function(results) {
sendResults(node,send,msg._msgid,results,false);
if (handleNodeDoneCall) {
diff --git a/packages/node_modules/@node-red/nodes/locales/en-US/messages.json b/packages/node_modules/@node-red/nodes/locales/en-US/messages.json
index 9c055d47b..7fc5912bb 100644
--- a/packages/node_modules/@node-red/nodes/locales/en-US/messages.json
+++ b/packages/node_modules/@node-red/nodes/locales/en-US/messages.json
@@ -248,7 +248,8 @@
"initialize": "On Start",
"finalize": "On Stop",
"outputs": "Outputs",
- "modules": "Modules"
+ "modules": "Modules",
+ "timeout": "Timeout (ms)"
},
"text": {
"initialize": "// Code added here will be run once\n// whenever the node is started.\n",
diff --git a/packages/node_modules/node-red/settings.js b/packages/node_modules/node-red/settings.js
index ac58f280a..28148d7b6 100644
--- a/packages/node_modules/node-red/settings.js
+++ b/packages/node_modules/node-red/settings.js
@@ -539,4 +539,8 @@ module.exports = {
// * - reason: if result is false, the HTTP reason string to return
// */
//},
+ /** The following property can be used to specify the defaultTimeout Value for function nodes.
+ */
+ //defaultFunctionNodeTimeout:1000
+ defaultFunctionNodeTimeout:1000,
}