mirror of
https://github.com/node-red/node-red.git
synced 2025-12-27 07:31:07 +01:00
Apply suggestions from code review
This commit is contained in:
@@ -399,8 +399,8 @@ module.exports = function(RED) {
|
||||
if(node.timeout>0){
|
||||
finOpt.timeout = node.timeout;
|
||||
finOpt.breakOnSigint = true;
|
||||
} else if(RED.settings.defaultFunctionTimeout > 0){
|
||||
finOpt.timeout = RED.settings.defaultFunctionTimeout * 1000
|
||||
} else if (RED.settings.globalFunctionTimeout > 0){
|
||||
finOpt.timeout = RED.settings.globalFunctionTimeout * 1000
|
||||
}
|
||||
}
|
||||
var promise = Promise.resolve();
|
||||
@@ -417,13 +417,12 @@ module.exports = function(RED) {
|
||||
var opts = {};
|
||||
if (node.timeout>0){
|
||||
opts = node.timeoutOptions;
|
||||
} else if(RED.settings.defaultFunctionTimeout > 0){
|
||||
opts.timeout = RED.settings.defaultFunctionTimeout * 1000
|
||||
} else if (RED.settings. globalFunctionTimeout > 0){
|
||||
opts.timeout = RED.settings. globalFunctionTimeout * 1000
|
||||
}
|
||||
try {
|
||||
node.script.runInContext(context,opts);
|
||||
} catch (err) {
|
||||
node.error(err);
|
||||
return done(err);
|
||||
}
|
||||
context.results.then(function(results) {
|
||||
|
||||
30
packages/node_modules/node-red/settings.js
vendored
30
packages/node_modules/node-red/settings.js
vendored
@@ -473,7 +473,7 @@ module.exports = {
|
||||
* - fileWorkingDirectory
|
||||
* - functionGlobalContext
|
||||
* - functionExternalModules
|
||||
* - defaultFunctionTimeout
|
||||
* - globalFunctionTimeout
|
||||
* - functionTimeout
|
||||
* - nodeMessageBufferMaxLength
|
||||
* - ui (for use with Node-RED Dashboard)
|
||||
@@ -502,27 +502,17 @@ module.exports = {
|
||||
|
||||
|
||||
/**
|
||||
* Default function timeout (in seconds) for the Function node.
|
||||
* A value of 0 indicates no timeout is applied, meaning the function can run indefinitely.
|
||||
*
|
||||
* The default function timeout is designed to prevent blocking code in function nodes,
|
||||
* which could otherwise lead to a stalled or unresponsive main thread. For example,
|
||||
* the following code would block the event loop indefinitely:
|
||||
*
|
||||
* `while(1) {}`
|
||||
*
|
||||
* By specifying a `defaultFunctionTimeout`, such scenarios can be mitigated,
|
||||
* ensuring that long-running or infinite loops are terminated automatically after
|
||||
* the specified timeout duration.
|
||||
*
|
||||
* Note: If both `defaultFunctionTimeout` and `functionTimeout` are defined in the
|
||||
* settings file, `functionTimeout` takes precedence, providing a more granular
|
||||
* control for individual function nodes.
|
||||
* The default timeout (in seconds) for all Function nodes.
|
||||
* Individual nodes can set their own timeout value within their configuration.
|
||||
*/
|
||||
globalFunctionTimeout: 0,
|
||||
|
||||
defaultFunctionTimeout: 0,
|
||||
|
||||
/** Default timeout, in seconds, for the Function node. 0 means no timeout is applied */
|
||||
/**
|
||||
* Default timeout, in seconds, for the Function node. 0 means no timeout is applied
|
||||
* This value is applied when the node is first added to the workspace - any changes
|
||||
* must then be made with the individual node configurations.
|
||||
* To set a global timeout value, use `globalFunctionTimeout`
|
||||
*/
|
||||
functionTimeout: 0,
|
||||
|
||||
/** The following property can be used to set predefined values in Global Context.
|
||||
|
||||
Reference in New Issue
Block a user