content icon indicating copy to clipboard operation
content copied to clipboard

Clarify when the rejectionhandled event does and does not fire

Open sideshowbarker opened this issue 3 years ago • 1 comments
trafficstars

Fixes https://github.com/mdn/content/issues/22177. @bergus it would great to have your review on this, if you can make time — since it’s based on your wording from https://stackoverflow.com/a/57261820/441757

sideshowbarker avatar Nov 09 '22 08:11 sideshowbarker

Preview URLs

(this comment was updated 2022-11-25 08:37:34.917907)

github-actions[bot] avatar Nov 09 '22 08:11 github-actions[bot]

I'd recommend to rather change the part "whenever a JavaScript Promise is rejected but after the promise rejection has been handled". I'd write

The **`rejectionhandled`** event is sent to the script's global scope (usually {{domxref("window")}} but also {{domxref("Worker")}}) whenever a rejected JavaScript {{jsxref("Promise")}} is handled late, after its rejections had caused an {{domxref("Window.unhandledrejection_event", "unhandledrejection")}} event, by subsequently attaching a handler.

This can be used in debugging and for general application resiliency, in tandem with the `unhandledrejection` event, which is sent when a promise is rejected but there is no handler for the rejection at the time.

bergus avatar Nov 12 '22 18:11 bergus

@bergus Thanks much — made it so

sideshowbarker avatar Nov 13 '22 04:11 sideshowbarker

@Josh-Cena It's usually not the unhandledrejection listener that would attach this handler, but some other code that still has a reference to the promise.

bergus avatar Nov 15 '22 08:11 bergus

Thanks, all. I will merge this shortly 👍🏻

bsmth avatar Nov 25 '22 08:11 bsmth