【发布时间】:2022-02-06 23:03:36
【问题描述】:
我正在开发一些 Azure Functions - 我正在从 CosmosDB 中读取一些文档,并对这些文档执行一些操作。
我遇到过以下代码,但不是很明白。
- 为什么要使用
then(),难道不可以直接在resolve()部分中删除它以及执行我想要的任何操作的代码吗?
所以:
const promises = documents.map(document =>
Promise.resolve().then(async () => {
// Do some stuff on the document
})
);
return Promise.all(promises).then();
对比:
const promises = documents.map(document =>
Promise.resolve(async () => {
// Do some stuff on the document
})
);
return Promise.all(promises).then();
【问题讨论】:
-
.then()似乎也很可疑,也许这不是最好的学习代码。
标签: typescript promise azure-functions azure-cosmosdb