-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Future.await doesn't propagate cancelation signal to future #515
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
Comments
It is done so by design. The same approach is used in
If |
Ah, I see. thanks for explanation. As for naming, I don't have any good suggestions only if awaitWithCancelation(), which is superLongJavaName =\ What do you think about parameter with default in await() function? PS Currently I miss one thing in the whole picture. Do you have the same issue with Deferred? its await function propagates cancelation, though nothing stops you from sharing this Deferred and await from two different coroutine contexts. |
@svasilinets did you notice this behaviour accidentally or did it arise from a real problem which is hard to resolve without cancellation?
Yes, though I'm not sure it is an issue. The simplest solution is to provide some boolean default parameter in |
I notice it accidentally, just exploring this topic, because we're going to expose ListenableFuture in our java api and have corresponding suspend functions in Kotlin apis. I thought and browse code a bit and now I think that default behavior for ListenableFuture.await() should be propagate cancelation (instead of current one), for following reasons:
So it will be weird that this behavior breaks on the edge of two frameworks that have the same defaults. PS. In guava there is special nonCancellationPropagating if anyone wants to stop propagation. |
It is not a default for |
Yeah, I was confused by that differences between cancelation+deferred and cancelation+suspend functions. So yeah, it makes sense to align However, I find this behavior for Deferred surprising as well, for the exact "isomorphism" reasons you described. But I'm not sure what is your position on it: is it WAI or is it something that you want to tweak? |
Ok I found this issue and it answers my question. In my humble opinion, once you've done those mentioned changes and it'd make sense to reiterate on decision about futures, because right now in similar fashion all future are always "global". However, I acknowledge that it is no straightforward way to apply same pattern to futures as you do for child coroutines. |
…, provide ListenableFuture.asDeferred Rationale: in most common use-cases awaiting the future is required to integrate with future-based API, current coroutine is the only user of this future and after its cancellation this future result is no longer needed. For non-cancelling await future.asDeferred().await() should be used Fixes #515
…, provide ListenableFuture.asDeferred Rationale: in most common use-cases awaiting the future is required to integrate with future-based API, current coroutine is the only user of this future and after its cancellation this future result is no longer needed. For non-cancelling await future.asDeferred().await() should be used Fixes #515
invokeOnCancellation only clears a reference to future in that coroutine
kotlinx.coroutines/integration/kotlinx-coroutines-guava/src/ListenableFuture.kt
Line 129 in 07c5ce4
The text was updated successfully, but these errors were encountered: