How do I cancel long running operation when a cour...
# coroutines
m
How do I cancel long running operation when a couroutine is cancelled ? I know I can somehow use
isActive
, but here I would want to provide some kind of
onCancelled
callback. (here when I do cancel process is still present when doing
ps aux
)
m
thanks, is there any high level api for this ?
+ is it ok to launch coroutines inside
suspend...Coroutine
blocks ?
t
The API is simple
Copy code
suspendCancellableCoroutine {
            it.invokeOnCancellation { cancel the job }
            it.resume(return result)
        }
this is to wrap blocking call into a coroutine that can be cancelled.
u
On cancellation call kill