So <@U2E974ELT> I managed to test it but I had to ...
# coroutines
k
So @elizarov I managed to test it but I had to remove the
actor
construct. Now I am calling the
suspend
fun
loadProducts()
from a
runBlocking
block directly. The question remains how I could make the
runBlocking
block to wait for the
consumeEach
in
loadProducts()
to finish, controlling somehow the mock
channel
I return from the mocked
loadProducts()
in my test. I hope I did explained it well. Thank you in advance for your interest.
d
Why don't you just return the flowable from Room to your ViewModel and consume it from there, passing contexts and jobs all over isn't so good, usually the repository apis shouldn't have to know which context is running it... if you really need to make the Room Flowable into suspending, there are ways to do it without needing to decide the context and job upfront... testing would be much simpler then.
k
I don’t want to use the Flowable directly. I have great experience with RxJava and I would like to get comfortable with coroutines too. Also I think that in a couple of months Room and other 3rd party libs will have Kotlin coroutine Apis too. The context and the job are similar to the subscribeOn/observeOn and subscription from the Rx world. I am passing this down to the
producer
coroutine so I can cancel/close the channel.
d
You can pass the observable, just instead on subscribe/observeOn you use consumeEach
k
Yeah I am doing this in the repository implementation. I am hiding the Flowable type and resuming a Receiverchannel instead. This allows me to only expose Kotlin coroutine types in the APIs so I can switch to the “native” coroutines API when Room will provide them without the need to modify other parts of my application.