Hi <@UHAJKUSTU>, with the latest changes in kotlin...
# reaktive
m
Hi @Arkadii Ivanov, with the latest changes in kotlin 1.4 with Ktor, I can see we are able to run it in background on native if we run from
MainScope
already tested that on my project, so would it make sense if this is provided in Reaktive through coroutine-interop?
a
Hi, sorry but I don't get. What change in Reaktive would you like? AFAIK starting from Kotlin 1.4. Ktor uses native-mt coroutines. So you can just use the
-nmtc
version of Reaktive
coroutines-interop
module.
m
yes but you can’t do
singleFromCoroutine
because you cannot specify dispatcher. It’s always
Dispatcher.Unconfined
but maybe there could be some flexibility there
a
What are you trying to achieve? Why do you need a dispatcher there? What if you write:
Copy code
singleFromCoroutine {}
    .subscribeOn(ioScheduler)
And why do you want to run Ktor on a particular Dispatcher?
m
I have to run Ktor on Coroutines’ MainScope. Even if I use a dispatcher to run in background, I cannot run it unless I launch it through MainScope. So using singleFromCoroutine won’t work in this case. So I figured for interoperability with coroutines we could have some singleFromCoroutine that will launch the call in MainScope and allow providing a dispatcher to run it on.
This way we can do calls to Ktor with a reaktive stream.
It’s not a high priority thing but when upgrading to 1.4 we faced this issue since part of the reaktive stream was calling Ktor so we had to change this.
a
I would like to understand the case completely. 🙂 What was the exact issue?
m
Let me write down something more clear. Sorry for the confusion 😅
I am traveling now. I will send it once I am at my laptop.
a
Thanks! My thoughts are as follows. Ktor switches dispatchers under the hood. There should be no need to manually switch dispatchers for Ktor. The only thing that was not possible before 1.4 is switching threads before/after Ktor for data processing. Now it is possible.
Copy code
singleFromCoroutine { /* Call Ktor, does not matter what is the dispatcher/thread here */ }
    .observeOn(computationScheduler)
    .map { /* parse the response on background thread /* } 
    .observeOn(mainScheduler)
    .susbcribe(isThreadLocal = true) { /* Update the UI on main thread /* }