-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 bi-directional cancellation for Task.await and Task.asDeferred #2528
Conversation
fae9a2c
to
8a19514
Compare
8a19514
to
14d76d5
Compare
14d76d5
to
aca6db8
Compare
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.
Also, please don't forget to run ./gradlew apiDump
in order to updated our binary compatibility data (you can read more here).
If you are not ready to walk this extra mile, that's completely okay, just notify us
aca6db8
to
ec84eee
Compare
Thanks for the review @qwwdfsad , this should be ready for another look! The |
* [CancellationException]. | ||
* If the [cancellationTokenSource] is cancelled, then this function will throw a [CancellationException]. | ||
*/ | ||
@ExperimentalCoroutinesApi |
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.
Both of these could be combined to have cancellationTokenSource
be a default argument, but then I couldn't apply @ExperimentalCoroutinesApi
to just the new overload.
3988d1e
to
d66ae38
Compare
…t via passed in CancellationTokenSource
d66ae38
to
d200eb7
Compare
Thank you for the review and insights! I switched the implementation to an overload of I'm curious to hear your thoughts on the handling for when the passed-in |
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.
Almost there! Please take care of the test and I'll handle the rest minors and will ensure it makes it into the next release
6335f28
to
e902995
Compare
e902995
to
bf4ec96
Compare
Just saw that the tests failed again, I went ahead and removed a similar racing assertion from the |
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.
Great work, thanks!
I've opened #2786 with minor edits, will merge it and it's going to be the part of 1.5.1.
Awesome, thank you @qwwdfsad for your help and your time to review! |
This PR includes my proposed addition to the
play-services
integration to allow bi-directional cancellation forTask.await
andTask.asDeferred
, which in particular provides the hook to cancel a task via aCancellationToken
(which fixes #2527)Both
Task.asDeferred
andTask.await
now each have a new overload that takes a passed inCancellationTokenSource
. If theDeferred
/await
is cancelled, or if the receivingTask
is cancelled, then theCancellationTokenSource
will also be cancelled. In particular, this means that if theTask
will be cancelled when theCancellationTokenSource
is cancelled, cancelling theDeferred
/await
will cancel the underlyingTask
.The existing implementations of
Task.asDeferred
andTask.await
call into the new implementations, with a newly constructedCancellationTokenSource
that will result in a no-op upon being cancelled.