Does anyone know if coroutines have different beha...
# android
Does anyone know if coroutines have different behaviour depending on different versions of Android? I got something like
launch(UI){ async(CommonPool, parent=myJob){mySuspendFunction()}.await()}
and when I cancel that job (
) 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 request
Did you try this several times? Whether cancellation works may depend on when the cancel request comes in...what does your
look like?
Copy code
suspend fun myFunc() = suspendCancellableCoroutine{continuation->
     val disposable =   anObservable().subscribe(onSuccess={continuation.resume(it)})

        continuation.invokeOnCompletion(onCancelling = true) {
something like that
Why do you use suspendCancellableCoroutine instead of kotlinx.coroutines integration with RxJava?
@julioyg That function will not cancel (and not even suspend) if the future already has a result ready for instance...might be a factor. Otherwise, it should be cancellable.
sorry, forgot about that I'm calling
, modifiying the question
@gildor I'm using that coz I didn't know about such integration, looking for it now
but still... would that change anything?
and why does it work on devices 8 and above?
ignores the cancelation request
What do you mean? invokeOnCompletion not called?
Maybe you could provide sample project with reproduction of this problem
it doesn't execute that code, correct
@julioyg are you sure that you don’t lock all the threads of CommonPool, so this just do not allow to execute any other coroutine? try to add
before subscription with some background scheduler ( 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 integration
thanks a lot, using another thread for my observable's worked about calling twice to
i got that controlled, but thank you so much for pointing that out
also you don’t need
onCancelling = true
, CancelableContinuation doesn’t not have “cancelling” state and just ignore this argument