我在我的应用程序中同时使用这两种。Kotlin Coroutines
用于单个交互,例如DB或API调用。同时,我还使用RxJava Flowable
来观察传感器事件。
Kotlin Coroutines
有dispatches
,RxJava
有shedulers
。它们的思想是提供最大效率的线程池,其大小取决于硬件配置。
因此,如果同时使用这两个线程,例如,我可以有8个正在运行的线程,4个在Dispatchers.Default
中,4个在Shedulers.computation
中,而不是4个线程。
所以我的问题是
有没有办法使用
Kotlin Dispatchers
作为RxJava shedulers
,反之亦然? 或者我应该定义我自己的executors
,并从它们构建dispatchers
和shedulers
?
发布于 2018-11-15 04:11:53
您可以使用kotlinx-coroutines-rx2
扩展库(https://github.com/Kotlin/kotlinx.coroutines/tree/master/reactive/kotlinx-coroutines-rx2) ....and,特别是Scheduler.asCoroutineDispatcher
https://stackoverflow.com/questions/53317641
复制