gpt4 book ai didi

Azure 函数 - 应该在每个循环之后或结束时调用 context.done

转载 作者:行者123 更新时间:2023-12-02 08:01:21 25 4
gpt4 key购买 nike

在 Azure 函数中,假设我有:

const cosmosDBTrigger: AzureFunction = async function (context: Context, documents: any[]): Promise<void> {
if (!!documents && documents.length > 0) {
documents.forEach(function (document) {
context.bindings.outputdocuments = document
//1 - SHOULD IT GO HERE
});
}
//2 - SHOULD IT GO HERE
}

放置 context.done 的正确位置是位置 1 还是位置 2。即应该位于循环中最后的每个文档之后?

谢谢。

最佳答案

我不确定它在 Node js 中是如何完成的,但我认为应该是这样的

const cosmosDBTrigger: AzureFunction = async function (context: Context, documents: any[]): Promise<void> {
if (!!documents && documents.length > 0) {
context.bindings.outputdocuments = documents;
}
context.done();
}

您只写了最后一个文档的原因是,如果您这样做

context.bindings.outputdocuments = document

这意味着您通过循环覆盖最后一个文档的输出,而不是提供数组。

关于Azure 函数 - 应该在每个循环之后或结束时调用 context.done,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55644026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com