Azure functions for wait在异步函数内部失败

Azure functions for wait在异步函数内部失败,azure-functions,Azure Functions,在异步Azure函数中使用“for await”会生成以下错误: 异常:工作程序无法加载函数HttpTrigger:“SyntaxError:意外保留字” 堆栈:D:\home\site\wwwroot\HttpTrigger\index.js:19 用于等待(blobServiceClient.listContainers()的常量容器){ ^^^^^ SyntaxError:意外的保留字 请注意,await在异步函数中使用,它应该可以工作: module.exports = async fu

在异步Azure函数中使用“for await”会生成以下错误:

异常:工作程序无法加载函数HttpTrigger:“SyntaxError:意外保留字” 堆栈:D:\home\site\wwwroot\HttpTrigger\index.js:19 用于等待(blobServiceClient.listContainers()的常量容器){ ^^^^^

SyntaxError:意外的保留字

请注意,await在异步函数中使用,它应该可以工作:

module.exports = async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request!!!!');

    const {ManagedIdentityCredential } = require ("@azure/identity")
    const { BlobServiceClient } = require("@azure/storage-blob"); // Change to "@azure/storage-blob" in your package

    let cred = new ManagedIdentityCredential()
    let myStr = ""    

    const blobServiceClient = new BlobServiceClient(
        // When using AnonymousCredential, following url should include a valid SAS or support public access
        `https://leonbragtest.blob.core.windows.net`,
        cred
      );

    let i = 1;

    (async () => {
        for await (const container of blobServiceClient.listContainers()) {
        console.log(`Container ${i++}: ${container.name}`);
        myStr += `Container ${i++}: ${container.name} `
        }
    })()

    context.res = {
        status: 200,
        body: "Time is:" + new Date() + "<br/>" + myStr
    };

};
module.exports=异步函数(上下文,请求){
log('JavaScript HTTP触发器函数处理了一个请求!!!!');
const{ManagedIdentityCredential}=require(@azure/identity)
const{BlobServiceClient}=require(@azure/storage blob”);//在包中更改为“@azure/storage blob”
让cred=newmanagedEntityCredential()
让myStr=“”
const blobServiceClient=新的blobServiceClient(
//使用匿名凭据时,以下url应包括有效的SAS或支持公共访问
`https://leonbragtest.blob.core.windows.net`,
信誉
);
设i=1;
(异步()=>{
用于等待(blobServiceClient.listContainers()的常量容器){
log(`Container${i++}:${Container.name}`);
myStr+=`Container${i++}:${Container.name}`
}
})()
context.res={
现状:200,
正文:“时间是:“+newdate()+”
“+myStr }; };
删除内部异步包装时,将生成相同的错误

在异步函数内部调用wait有什么不对?

已解决。
Azure func运行时不支持“for await”(正如我指出的那样)。使用iter是可行的。

Hi,您可以将您的解决方案作为答案。这将帮助其他人快速找到问题。