https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

jw

11/07/2017, 12:59 AM
there doesn't seem to be a cancelation hook when building a
Deferred
(via
CompletableDeferred
). Is there something else that offers this callback?
e

elizarov

11/07/2017, 6:58 AM
invokeOnCompletion
is there. Or what else are you looking for?
j

jw

11/07/2017, 7:20 AM
I'm wrapping Retrofit's Call. It completes with a result or completes exceptionally. I want to propagate cancellation of the Deferred up into the Call though.
e

elizarov

11/07/2017, 7:25 AM
Use
invokeOnCompletion
and cancel call from there. It should work assuming that cancelling an otherwise completed call has no effect.
j

jw

11/07/2017, 7:28 AM
It's meant to be cheap.
e

elizarov

11/07/2017, 7:36 AM
You can also extend
JobSupport
just like
CompletableDeferred
. In this case,
onCancellation
can be overriden. Less stable API, but less overhead.
j

jw

11/07/2017, 10:52 PM
Can you clarify what you mean by less stable? I thought binary compatibility was guaranteed despite the experimental status.
Ah, I think I see it. There are warnings that it is an unstable API.
3 Views