javascript - Azure 函数中的异步函数

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

我在 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 异步语法支持,您需要安装最新版本的 cli 以及节点 v8.x

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

此外,您还需要 enable the beta runtime on azure所以它在部署时也有效。

关于javascript - Azure 函数中的异步函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48112327/

相关文章:

python - Azure Functions 部署时无法运行

javascript - 类属性的必要性,以定位 div 层

JavaScript:检查是否按下了 CTRL 按钮

c# - 设置超时时 HttpClient 挂起 (Windows Phone)

async-await - 如何等待订阅功能以角度 8 完成?

c# - Azure Function,返回状态码+JSON,无需在每个逻辑部分定义返回

python - Dill 无法在其他环境中反序列化

javascript - 如何从 jquery datepicker 计算年龄?

javascript - 如何使用 Javascript 数组从涉及多个键值对的 JSON 中检索特定值

c# - 为什么在使用 ContinueWith 时会收到编译器警告?