julioyg
04/24/2018, 3:08 PMlaunch(UI){ async(CommonPool, parent=myJob){mySuspendFunction()}.await()}
and when I cancel that job (myJob.cancel()
) either on my pixel2 running 8.1 or an emulator running the same version it works nicely, but when I run the same code in a nexus 5x running 7.1 it just ignores the cancelation requestpetersommerhoff
04/24/2018, 3:11 PMmySuspendFunction
look like?julioyg
04/24/2018, 3:14 PMsuspend fun myFunc() = suspendCancellableCoroutine{continuation->
val disposable = anObservable().subscribe(onSuccess={continuation.resume(it)})
continuation.invokeOnCompletion(onCancelling = true) {
disposable.dispose()
}
}
julioyg
04/24/2018, 3:14 PMjulioyg
04/24/2018, 3:16 PMgildor
04/24/2018, 3:18 PMpetersommerhoff
04/24/2018, 3:19 PMjulioyg
04/24/2018, 3:21 PMawait()
, modifiying the questionjulioyg
04/24/2018, 3:21 PMjulioyg
04/24/2018, 3:23 PMjulioyg
04/24/2018, 3:30 PMgildor
04/24/2018, 3:33 PMignores the cancelation requestWhat do you mean? invokeOnCompletion not called?
gildor
04/24/2018, 3:35 PMjulioyg
04/24/2018, 3:51 PMgildor
04/24/2018, 3:54 PMobserverOn
before subscription with some background scheduler (Schedulers.io() for example)
In general your integration with RxJava is not completed and not particularly correct (for example if observable emit more than one item, your code will crash on contuninuation.resume() call, also you do not handle case of empty observable).
Try to check threads and use kotlinx.coroutines rx integrationjulioyg
04/24/2018, 4:18 PMresume()
i got that controlled, but thank you so much for pointing that outgildor
04/24/2018, 4:30 PMonCancelling = true
, CancelableContinuation doesn’t not have “cancelling” state and just ignore this argument