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

elizarov

06/07/2018, 8:30 AM
@spand It does not really matter if
Job()
had completed “normally” or “was cancelled”. You can tell the difference (between normal completion and cancellation) with
isCancelled
and that is the only difference. Just use
cancel()
in all cases and don’t use
isCancelled
.
g

gildor

06/07/2018, 8:31 AM
do you mean don’t use
isCompleted
?
Becausae isCompleted is true for any (cancelled or finished normally coroutine)
e

elizarov

06/07/2018, 8:32 AM
You should use
isCompleted
. That is how you can tell whether your “lifecycle” has completed or not. You should not use
isCancelled
because the difference between “completed normally” and “cancelled” is quite superfluous.
g

gildor

06/07/2018, 8:33 AM
yeah, from point of view of lifecycle, sure, got your point
I think we already had discussion in this channel about “how to detect that coroutine finished without cancellation”
e

elizarov

06/07/2018, 8:37 AM
I, for one, question the very need to be able to make this distinction. See here: https://github.com/Kotlin/kotlinx.coroutines/issues/220
s

spand

06/07/2018, 8:41 AM
Thanks for the reply. I just expected the lib to have different behavior depending on cancellation/normal completion so I try to keep the code aligned with my intentions.. but if not then great 🙂
4 Views