Matias Reparaz
11/12/2021, 1:18 PMfun 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:
fun doSomething(param: SomeParams): Single<Something> = Single.just(
runBlocking {
doSomething()
}
)
suspend fun doSomething(): Something = TODO()
Thanksmkrussel
11/12/2021, 1:26 PMSingle.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.htmlMatias Reparaz
11/12/2021, 1:32 PM