Do Promise.allSettled trigger catch block in any case? #551
Unanswered
pugazhendhis
asked this question in
Content
Replies: 0 comments 1 reply
-
It doesn't in most conceivable cases, but just for the fun of it, you can indeed trigger rejections in some corner cases: // An iterable that throws when iterated
Promise.allSettled({ get [Symbol.iterator]() { throw new Error("No iterator"); } }).catch(console.log);
Promise.allSettled((function* () { throw new Error("Can't iterate me"); })()).catch(console.log);
// Calling allSettled on an incompatible constructor
Promise.allSettled.call(Number).catch(console.log); // TypeError: Promise resolve or reject function is not callable ...but in general you don't have to worry about that and I find it too obscure to be documented. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Example code:
I know that
Promise.allsettled
returns array of settled (resolve/reject) Promise.But above snippet returns
success
from then callback thoughpromise2 rejects
.My question is in which scenario
failure
from catch callback will trigger?Beta Was this translation helpful? Give feedback.
All reactions