我试图弄清楚如何在函数结束之前等待多个承诺的执行。
本质上,这就是我尝试做的:
这是我到目前为止所尝试的:
A)主要功能(启动第一级承诺):
export function cleanUpAllData(user) {
const userId = user.uid;
const promises = [];
promises.push(deleteCategoriesData(userId)); // this works fine
promises.push(deleteUserAndGroupData(userId)); // this one has other promises which still run when Promise.all() is finished
Promise.all(promises)
.then(() => {
return "ok"; // this works so far, but not all promises are resolved
})
.catch(errPromises => {
console.log("an error occured during the processing of main promises");
console.log(errPromises, errPromises.code);
return "error";
})
}
Run Code Online (Sandbox Code Playgroud)
B)deleteUserAndGroupData 函数(另一个 Promise 工作正常):在用户数据中找到的每个组启动另一个级别的 Promise,并且还触发第三个级别的 Promise(deleteGroup) …
promise firebase google-cloud-functions google-cloud-firestore