Hey. I’m going through the Coroutines docs and I’m...
# coroutines
m
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
You might want to make sure a coroutine releases a resource before you access it?
b
You can call
cancel()
on a Coroutine that's already completed exceptionally.
r
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