【发布时间】:2021-01-13 13:13:24
【问题描述】:
我正在使用此处记录的 Cloud Firestore 触发器。 https://firebase.google.com/docs/functions/firestore-events
如何从这些函数之一运行异步代码?这是我想做的一个例子。
async function doSomething(data) {
// ...
}
exports.updateUser = functions.firestore
.document('users/{userId}')
.onUpdate((change, context) => {
await doSomething(change.after.data());
});
当我尝试部署此功能时,我收到此错误消息。
return await doSomething(change.after.data());
^^^^^
SyntaxError: await is only valid in async function
【问题讨论】:
标签: javascript firebase google-cloud-firestore async-await