azure-functions - 使用 context.done() 后我会得到 Promise 吗?

标签 azure-functions

我遵循了 MS 编写 Azure Function 的所有准则。无论如何必须使用 .done() 否则客户端(Postman)将看不到任何返回:

module.exports = async function(context)
{
  ...
  const result = await aPromise().catch((bad)=>
    {
    context.res = {status: 401, body: "bad"};
    context.done();  // needed so client can get the above res
    });
}

这是否意味着返回不是一个Promise

最佳答案

如果您的函数是同步,它不会返回Promise,因此您必须传递context对象,就像调用正确使用需要 context.done

//您应该包含上下文,其他参数是可选的

module.exports = function(context, yourTrigger, yourInput) {
    // your function code
    context.done();
};

enter image description here

如果你的函数是async function 。您不需要调用 context.text。 在 Functions 运行时的异步函数声明中,您不需要显式调用 context.done回调以表明您的功能已完成。

从函数版本2.x开始适用。如果您使用的是函数版本 1.x,您需要调用 context.done 回调。

module.exports = async function (context) {
    context.log(‘your log');
};

enter image description here

注意:

在编写异步函数时,不需要显式调用donedone回调会被隐式调用。

引用here了解更多信息

关于azure-functions - 使用 context.done() 后我会得到 Promise 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70965346/

相关文章:

c# - 有没有一种方法可以在 azure 函数启动后立即调用通过依赖项注入(inject)注入(inject)的类中的方法?

python - 如何在python的azure函数中使用req.get_body(),其目的是什么?

azure - 组织函数应用程序从 azure devops 进行部署 - 管道 CI/CD

azure - 如何使用 Spring Boot 应用程序通过 Azure Functions 安排 Cosmos DB 数据处理

c# - Azure 函数 - 队列触发器将 DateTimeOffset 返回为 null

azure - 如何在 Azure 函数中显式放弃由主题消息/订阅触发的消息?

node.js - 如何从多个 Azure Functions TypeScript API 端点连接到 Azure SQL 数据库

azure - HTTP 触发器 Azure 函数中的 HTTP 监听器

asp.net-core - Azure 函数 : host error has occurred during startup operation Could not load file

.net - Azure 服务总线将获取请求添加到队列