4 ms·
Promise 3's rejection would be awaited and handled after promise 2. Yes, it might finish over the network before promise 1, but it won't be realized by the pro
by clarkdale 4y ago
Promise 3's rejection would be awaited and handled after promise 2.
Yes, it might finish over the network before promise 1, but it won't be realized by the program until its await occurs in the for loop.
- DecoPerson 4y agoThe issue is that V8 unhandled rejection logic doesn’t wait until the promise is awaited. If a promise is rejected, has no awaiter (.then/.catch/await), and persists in this state for some amount of time/event-loops (that the article covers), it will be treated as unhandled. I tested this in Node 18. It treats it as unhandled. The only way to avoid the gotcha’s described in the article is to ensure all promises: - cannot fail, and/or - are immediately awaited (by anything but .catch is the easiest).