-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add awaitCancellation() #2225
Conversation
Resolves issue Kotlin#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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
Merged. |
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