Skip to content

Update Promise.race documentation regarding error handling#44286

Open
mb-realpage wants to merge 1 commit into
mdn:mainfrom
mb-realpage:patch-1
Open

Update Promise.race documentation regarding error handling#44286
mb-realpage wants to merge 1 commit into
mdn:mainfrom
mb-realpage:patch-1

Conversation

@mb-realpage
Copy link
Copy Markdown

@mb-realpage mb-realpage commented May 28, 2026

Clarified that capturing and clearing the timeout handle is not required when using Promise.race to time out a request. Provided an example to illustrate this point.

Description

Expanded the description of "Using Promise.race() to implement request timeout" to demonstrate how the timeout does not need to be captured to prevent the throwing of the error: every iterable item passed to Promise.race that loses the race is consumed silently, so the error is thrown but does not become an unhandledRejection.

Motivation

I refactored a significant chunk of code to use Promise.race and an auto-throwing method, then worried that the timeouts might be generating unhandled rejections; after checking the MDN, I didn't see any reference to this specific case. So I developed a "solution" that promptly created the problem I was trying to avoid.

Additional details

None.

Related issues and pull requests

None.

Clarified that capturing and clearing the timeout handle is not required when using `Promise.race` to time out a request. Provided an example to illustrate this point.
@mb-realpage mb-realpage requested a review from a team as a code owner May 28, 2026 21:45
@mb-realpage mb-realpage requested review from Josh-Cena and removed request for a team May 28, 2026 21:45
@github-actions github-actions Bot added Content:JS JavaScript docs size/s [PR only] 6-50 LoC changed labels May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:JS JavaScript docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants