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 14c8e9d49..a6573a787 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,7 +96,7 @@ module.exports = function(RED) { node.fin = n.finalize ? n.finalize : ""; var handleNodeDoneCall = true; - + // Check to see if the Function appears to call `node.done()`. If so, // we will assume it is well written and does actually call node.done(). // Otherwise, we will call node.done() after the function returns regardless. @@ -105,7 +105,7 @@ module.exports = function(RED) { } var functionText = "var results = null;"+ - "results = (function(msg,__send__,__done__){ "+ + "results = (async function(msg,__send__,__done__){ "+ "var __msgid__ = msg._msgid;"+ "var node = {"+ "id:__node__.id,"+ @@ -284,14 +284,14 @@ module.exports = function(RED) { } function processMessage(msg, send, done) { - try { - var start = process.hrtime(); - context.msg = msg; - context.send = send; - context.done = done; + var start = process.hrtime(); + context.msg = msg; + context.send = send; + context.done = done; - node.script.runInContext(context); - sendResults(node,send,msg._msgid,context.results,false); + node.script.runInContext(context); + context.results.then(function(results) { + sendResults(node,send,msg._msgid,results,false); if (handleNodeDoneCall) { done(); } @@ -302,7 +302,7 @@ module.exports = function(RED) { if (process.env.NODE_RED_FUNCTION_TIME) { node.status({fill:"yellow",shape:"dot",text:""+converted}); } - } catch(err) { + }).catch(err => { if ((typeof err === "object") && err.hasOwnProperty("stack")) { //remove unwanted part var index = err.stack.search(/\n\s*at ContextifyScript.Script.runInContext/); @@ -340,7 +340,7 @@ module.exports = function(RED) { else { done(JSON.stringify(err)); } - } + }); } const RESOLVING = 0;