https://kotlinlang.org logo
Title
d

Dmytro Danylyk

11/07/2018, 3:57 AM
So rx java has a way to inject scheduler, is there a plan to have similar thing for coroutines dispatchers? I want to test my code which rely on 3rd party component. This component doesn’t provide way to change dispatcher.
kotlin
// library
class Componenet {

   fun doSomething() {
       launch { // long running operation }
   }
}

// client
fun test() {
    Componenet().doSomething()
   // I want to wait until doSomething is finished but I can't
}
👍 1
3
m

mayojava

11/07/2018, 5:30 AM
I guess you mean something similar to RxJavaPlugins
g

gildor

11/07/2018, 5:55 AM
I would add +1 for this. Replacing dispatcher implementation is pretty common thing which of course can be solved by DI, but this adds not necessary boilerplate especially for functions and Inline classes (I have use case when would like to use Inline class to wrap blocking API with coroutines, but cannot because want to allow switch dispatcher) This is also crucial for UI dispatcher and unit tests. I agree that in most cases it can be handled by DI but a way to replace default dispatchers sounds reasonable for me