从 cloudfunctions 在 firestore 中设置数据时是否需要使用 await
Is there any need to use await when setting data in firestore from cloudfunctions
我有一个 运行 相当慢的网络应用程序,并且有一些云函数用于 update/set firestore
中的值
当我更新 firestore 数据库中的值时,我应该等待请求完成,还是我可以相信请求已发送并且数据会被更新?
换句话说,对于下面的函数,await 语句是否有助于计算,还是只是增加了我使用的 CPU 时间?
exports.exampleFunction = functions.https.onRequest(async (request, response)=> {
await db.collection('users').doc(request.body.userID).update({
username: request.body.username
})
response.send({done: true})
return ;
})
谢谢:)
您可以参考 Whosebug Answer Doug 解释了从函数中删除 await 的后果。
您还可以参考 Documentation,其中解释了管理函数生命周期的重要性。
When you return a JavaScript promise to a function, that function keeps running until the promise is resolved or rejected. To indicate that a function has
completed its work successfully, the promise should be resolved. To indicate an error, the promise should be rejected. This means you only need to handle
errors that you want to.
我有一个 运行 相当慢的网络应用程序,并且有一些云函数用于 update/set firestore
中的值当我更新 firestore 数据库中的值时,我应该等待请求完成,还是我可以相信请求已发送并且数据会被更新?
换句话说,对于下面的函数,await 语句是否有助于计算,还是只是增加了我使用的 CPU 时间?
exports.exampleFunction = functions.https.onRequest(async (request, response)=> {
await db.collection('users').doc(request.body.userID).update({
username: request.body.username
})
response.send({done: true})
return ;
})
谢谢:)
您可以参考 Whosebug Answer Doug 解释了从函数中删除 await 的后果。
您还可以参考 Documentation,其中解释了管理函数生命周期的重要性。
When you return a JavaScript promise to a function, that function keeps running until the promise is resolved or rejected. To indicate that a function has completed its work successfully, the promise should be resolved. To indicate an error, the promise should be rejected. This means you only need to handle errors that you want to.