【问题标题】:async function in an Azure FunctionAzure 函数中的异步函数
【发布时间】:2018-01-05 11:07:33
【问题描述】:

我在 Azure 中遇到此 javascript 函数定义错误。我在 Azure 函数中定义它以供导出的函数使用。

async function getData() {
    var data = await postRequest();
    return data;
};

以下是我在控制台中遇到的错误。 Azure 函数是否不支持异步等待语法?

如果是,我将如何实现异步调用(例如使用 node-rest-client 进行的 REST 调用)。

2018-01-05T10:50:55.448 Function started (Id=a4995e6f-141a-46bb-becf-
468f49f7505d)
2018-01-05T10:50:55.565 Exception while executing function: 
Functions.MyFunctionName. mscorlib: One or more errors occurred. 
D:\home\site\wwwroot\MyFunctionName\index.js:90
async function getData() {
      ^^^^^^^^

SyntaxError: Unexpected token function
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at eval (eval at compileFunc (D:\Program Files (x86)\SiteExtensions\Functions\1.0.11388\bin\edge\double_edge.js:34:28), <anonymous>:1:80).
2018-01-05T10:50:55.673 Function completed (Failure, Id=a4995e6f-141a-46bb-becf-468f49f7505d, Duration=221ms)

【问题讨论】:

    标签: javascript async-await azure-functions azure-function-async


    【解决方案1】:

    对于 javascript 异步语法支持,您需要安装最新版本的 cli 以及 node v8.x

    npm i -g azure-functions-core-tools@core

    此外,您还需要enable the beta runtime on azure,以便在部署时也可以使用。

    【讨论】:

    • 我发现在部署后无法在 Azure 门户中启用 beta 运行时。我必须先创建一个新的函数应用并启用 beta 运行时。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 2020-10-14
    • 2019-01-20
    • 1970-01-01
    • 2022-11-16
    • 2016-08-09
    • 2012-07-25
    相关资源
    最近更新 更多