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

Conditionally create an instance of CancellationException in Channel.… #2384

Merged
merged 1 commit into from Nov 16, 2020

Conversation

qwwdfsad
Copy link
Member

…cancel()

Avoid creating costly exception when the channel is cancelled to save a few cycles when it's not necessary. Cancellation is heavy-enough when the channel is open, so the single check won't worsen it.

…cancel()

Avoid creating costly exception when the channel is cancelled to save a few cycles when it's not necessary. Cancellation is heavy-enough when the channel is open, so the single check won't worsen it.
Copy link
Contributor

@elizarov elizarov left a comment

Choose a reason for hiding this comment

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

👍 Good stuff

@qwwdfsad qwwdfsad merged commit bc553ba into develop Nov 16, 2020
@qwwdfsad qwwdfsad deleted the channel-cancel-fast-path branch November 16, 2020 19:23
@paulferaud
Copy link

This changed the behavior for completed callbackFlow that are still blocked. Example:

  @Test
  fun p2384() = runBlocking {
    val myFlow = callbackFlow<Any> {
      close()

      // Should throw?
      delay(Duration.INFINITE)
    }

    // Should complete?
    myFlow.collect()
  }

Here, delay used to throw a cancellation exception, and the flow would complete.
Now, it blocks on delay, and collect() never completes.

@qwwdfsad
Copy link
Member Author

Thanks for the report, that's an unexpected side-effect, filed #2506

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