Promise (fun_father) function contains the Promise (fun_son) function. If fun_father starts with resolve () and the fun_son is not finished, will the fun_son continue or terminate?
let status= 0
const fun_father= () => {
return new Promise((resolve, reject) => {
fun_son().then(() => {
status= 1
})
//......
resolve("fun_father done")
})
}
const fun_son = () => {
return new Promise((resolve ,reject) => {
//......
resolve("fun_son done")
})
}
fun_father().then(msg => {
console.log(msg)
})
I encounter this situation when writing a project. After simplification, it is similar to the above. I want to be able to print out "fun_father done" and change the status to 1. After writing this, the leader told me that it would be fine if fun_son executed faster than fun_father, but if otherwise, fun_son would terminate execution because fun_father returned and memory was freed. I still have doubts about this, but if I try it myself, there is no good way to test async (loops are useless). SetTimeout is OK, but it can"t be fully explained. Therefore, I would like to ask the bosses whether this method of writing is feasible.