Hi, I have an interface with a method like this `f...
# getting-started
m
Hi, I have an interface with a method like this
fun doSomething(param: SomeParams): Single<Something>
where Single is from RxJava. I want to use coroutines inside my implementation and wrap the value at the end. But how can I create the CoroutineContext? It’s ok to use the runBlocking in this context? something like this:
Copy code
fun doSomething(param: SomeParams): Single<Something> = Single.just(
   runBlocking {
        doSomething()
    }
)
suspend fun doSomething(): Something = TODO()
Thanks
m
Using
Single.just()
is probably a mistake, that will do the
runBlocking
when
doSomething
is called instead of when someone subscribes to the
Single
. That defeats the entire goal of being reactive. Also using
runBlocking
prevents cancellation. Kotlin provides library for doing this mapping. https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-rx2/kotlinx.coroutines.rx2/rx-single.html
👏 1
m
Thanks! This is what I was looking for!