Azure函数-应该在每个循环之后或结束时调用context.done [英] Azure function - should context.done be called after each loop or at end
本文介绍了Azure函数-应该在每个循环之后或结束时调用context.done的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Azure函数中说我有:
In an Azure function say I have:
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上是正确的位置吗?也就是说,应该在循环中每个文档的末尾吗?
Is the correct place to place context.done
be in position 1 or 2. Namely should be after each document in the loop at the very end?
谢谢.
推荐答案
我不确定它如何在节点js中完成,但我认为应该是这样的
I am not sure how its done in node js but I assume should be something like this
const cosmosDBTrigger: AzureFunction = async function (context: Context, documents: any[]): Promise<void> {
if (!!documents && documents.length > 0) {
context.bindings.outputdocuments = documents;
}
context.done();
}
原因是,您最后写的文件是
Reason you have only last document written is that if you do
context.bindings.outputdocuments = document
这意味着您通过循环覆盖了最后一个文档的输出,而不是提供一个数组.
It means that you overriding output by last document via loop instead of providing an array.
这篇关于Azure函数-应该在每个循环之后或结束时调用context.done的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文