Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't throw in awaitSignal if the timeout is canceled #1394

Merged
merged 1 commit into from
Dec 15, 2023

Conversation

swankjesse
Copy link
Member

No description provided.

Comment on lines +201 to +208
// If there's time remaining, we probably got the call we were waiting for.
if (nanosRemaining > 0) return

// Return without throwing if this timeout was canceled while we were waiting. Note that this
// return is a 'spurious wakeup' because Condition.signal() was not called.
if (cancelMark !== cancelMarkBefore) return

throw InterruptedIOException("timeout")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not my favorite control flow structure (within a try/catch), but probably is the most readable in the end.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this throw doesn’t get caught by the directly-enclosing try/catch. InterruptedIOException and InterruptedException are tricky.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was going to suggest moving the throw out of the try/catch, but then I really want the returns out of the try/catch too, but then local scoping becomes hard and it's all terrible and whatever this is fine.

@swankjesse swankjesse merged commit bf29a91 into master Dec 15, 2023
11 checks passed
@swankjesse swankjesse deleted the jwilson.1214.awaitSignal_cancel branch December 15, 2023 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants