Reputation: 2638
I'm using both in my app.
Kotlin Coroutines
are used for single interactions, such as a DB or an API call.
But also I'm using RxJava Flowable
to observe sensor events.
Kotlin Coroutines
has dispatches
, and RxJava
has shedulers
.
The idea of them is to provide maximally efficient thread pools, which size depends on hardware configuration.
So if I use both simultaneously, I can have, for example, 8 running threads, 4 in Dispatchers.Default
and 4 in Shedulers.computation
, instead of 4 threads.
So my question is
Is there a way use
Kotlin Dispatchers
asRxJava shedulers
or vise versa?Or I should define my own
executors
, and builddispatchers
andshedulers
from them?
Upvotes: 1
Views: 1499
Reputation: 10330
You can use kotlinx-coroutines-rx2
extension library (https://github.com/Kotlin/kotlinx.coroutines/tree/master/reactive/kotlinx-coroutines-rx2) ....and in particular Scheduler.asCoroutineDispatcher
Upvotes: 3