The problem is like this
function demo() {
return new Promise((resolve, reject) => {
...
// The problem here!!
//I just found in some rare case we failed to call resolve or reject
})
}
demo()
.then(res => {
console.log('resolve')
console.log(res)
})
.catch(rej => {
console.log('reject')
console.log(rej)
})
.finally(() => {
console.log('why')
})
When I failed to call resolve or reject, even the finally block is not called! Why ?
I had thought it was a bug then I found the original author seemed to do that on purpose that if he did not call either resolve or reject, none of then/catch/finally should be called, i.e. in that case no follow-up action should be taken.
But is this a valid way to handle the situation that no follow-up action should be taken ? Will it cause any trouble ?
----- update -----
Even though my question was marked duplicated I am still not satisfied with the answers I got. Originally I had thought it was a bad idea to let promise stay in pending state forever.
But the answer in that SO said "There should be no side effect."
Does never resolved promise cause memory leak? also said "In short - at least in modern browsers - you don't have to worry about unresolved promises as long as you don't have external references to them". So it seems ok to let promise stay in pending if that is the purpose.