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

Implement AsyncTimeout.cancel() #1396

Merged
merged 2 commits into from
Dec 16, 2023
Merged

Conversation

swankjesse
Copy link
Member

This is a simple implementation that uses 3 booleans to keep state (inQueue, isCanceled, hadTimeoutWhenCanceled). I'd like to do a follow-up change to replace 3 booleans with a proper state variable, especially since that eliminates some impossible states (like inQueue and isCanceled).

This is a simple implementation that uses 3 booleans
to keep state (inQueue, isCanceled, hadTimeoutWhenCanceled).
I'd like to do a follow-up change to replace 3 booleans with
a proper state variable, especially since that eliminates
some impossible states (like inQueue and isCanceled).
@@ -270,24 +294,22 @@ open class AsyncTimeout : Timeout() {

/** Returns true if the timeout occurred. */
private fun cancelScheduledTimeout(node: AsyncTimeout): Boolean {
Copy link
Member Author

Choose a reason for hiding this comment

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

GitHub’s UI doesn’t make it obvious, but the only change in this function is moving withLock() to the callsites.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks pretty good with "Hide whitespaces", although I might be biased cause I've already seen this code!

@@ -372,9 +372,124 @@ class AsyncTimeoutTest {
assertEquals(of(*data), target.readByteString())
}

@Test
fun enterCancelSleepExit() {
Copy link
Member Author

Choose a reason for hiding this comment

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

I’m self-satisfied with these test names

@swankjesse swankjesse merged commit 45d6834 into master Dec 16, 2023
11 checks passed
@swankjesse swankjesse deleted the jwilson.1215.async_timeout_cancel branch December 16, 2023 03:52
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

3 participants