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

marekabaffy

12/09/2018, 4:58 PM
Hey. I’m going through the Coroutines docs and I’m a bit confused about the
.cancelAndJoin()
method. What is it good for? Why would I want to wait until the coroutine actually finishes the cancellation? I bet there is a pretty clear use case, but I just can’t see it.
d

Dominaezzz

12/09/2018, 6:05 PM
You might want to make sure a coroutine releases a resource before you access it?
b

bdawg.io

12/10/2018, 1:47 AM
You can call
cancel()
on a Coroutine that's already completed exceptionally.
r

Rohan Maity

12/12/2018, 6:40 AM
Suppose user have clicked a button started a long task. Now user comes back after some time to app . Now he/she forgot that he has already started a long task and again clicks the button. Now in this case .cancelAndJoin() method can come I handy . You can cancel the already running coroutine , start again and wait for it until it finishes Otherwise it would have launched another coroutine
4 Views