在异步Azure函数中使用“ for await”会产生以下错误:
异常:工作者无法加载函数HttpTrigger:'SyntaxError:意外的保留字'堆栈:D:\ home \ site \ wwwroot \ HttpTrigger \ index.js:19等待(blobServiceClient.listContainers()的常量容器){^^^^^
SyntaxError:意外的保留字
请注意,async函数内部使用了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
};
};
当删除内部异步包装器时,会生成相同的错误。
我在异步函数内部调用await时出错了?
已解决。正如我所指出的那样,Azure func运行时不支持“等待”。使用iter工作。