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

Michal Fudala

12/16/2018, 11:39 AM
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

Michal Fudala

12/16/2018, 11:47 AM
thanks, is there any high level api for this ?
+ is it ok to launch coroutines inside
suspend...Coroutine
blocks ?
t

Tolriq

12/16/2018, 11:53 AM
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

uli

12/16/2018, 6:52 PM
On cancellation call kill
9 Views