Skip to content

Add awaitCancellation() #2225

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

Closed
wants to merge 5 commits into from
Closed

Conversation

LouisCAD
Copy link
Contributor

@LouisCAD LouisCAD commented Sep 2, 2020

I'm unsure about the relevance of the test and I couldn't run it on the JVM locally (because of #2224), but it succeeded in native (macosX64).

Feel free to make any suggestion regarding the files where the new code is, or suggest/perform edits to the doc.

Resolves #2213

/**
* Suspends until cancellation, in which case it will throw a [CancellationException].
*
* Handy because it returns [Nothing], allowing it to be used in any coroutine,
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, it would be great to show some small practical example here, if you have one in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added two examples. I failed to find simpler examples for now, but it's not public API so it can be changed in the future.

Also, I know trySend doesn't exist yet, but I thought it would look nicer than runCatching { offer(…) } or a try/catch.

@LouisCAD LouisCAD requested a review from elizarov September 14, 2020 01:28
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! I'm merge it manually with few changes.

@elizarov
Copy link
Contributor

Merged.

@elizarov elizarov closed this Sep 14, 2020
elizarov pushed a commit that referenced this pull request Sep 14, 2020
@LouisCAD LouisCAD deleted the await-cancellation branch September 14, 2020 14:05
recheej pushed a commit to recheej/kotlinx.coroutines that referenced this pull request Dec 28, 2020
recheej pushed a commit to recheej/kotlinx.coroutines that referenced this pull request Dec 28, 2020
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.

2 participants