【发布时间】:2021-06-15 07:51:21
【问题描述】:
我有一个 firebase 函数,它可以发送电子邮件、更新另一个集合中的记录并在创建新用户时在另一个 API 服务上创建一个帐户。整个操作运行了 2 分钟,但我认为它可以进一步优化。我也是异步等待的新手,所以我真的不知道如何正确使用它。
exports.onCreateUser = functions.firestore
.document('users/{userId}')
.onCreate((snap, context) => {
const updateOtherCollectionRecord = async () => {
const values...
...
return admin
.firestore()
.collection('others')
.doc('id')
.update(values);
}
const sendEmail = async () => {
const url...
...
return await axios
.post(url,data,config);
}
const createAccount = async () => {
const url...
...
return await axios
.post(url, data, config);
}
updateOtherCollectionRecord();
sendEmail();
createZendeskAccount();
})
现在,这些函数同步运行。我希望使用 Promise.all 进行重构,但不知道如何使用它。我试过了,但它没有触发功能。
【问题讨论】:
标签: javascript node.js firebase google-cloud-functions