boyw165
04/30/2023, 1:56 AMPascal How
07/25/2023, 11:16 AMrxSingle
or rxCompletable
so that they can still talk to other layers that were still in Rx.
We kept the Presentation layer in Rx, because of time constraint and project requirements (Takes too long to change everything in one go)
In some cases it can get ugly and we resorted to having runBlocking
in production code, which is not recommended. However, if your app still performs at an acceptable level then it is a valid trade offgildor
07/02/2024, 9:48 AMIn some cases it can get ugly and we resorted to havingCurious about your casesin production coderunBlocking
gildor
07/02/2024, 9:48 AMgildor
07/02/2024, 9:50 AMgildor
07/02/2024, 9:51 AMgildor
07/02/2024, 9:53 AMgildor
07/02/2024, 9:54 AMPascal How
07/02/2024, 11:11 AMrunBlocking
is because of how our code was architected and also timelines for project deliveries.
We wanted to migrate from RxJava to coroutines and we started introducing suspend functions for network calls and repositories.
At the same time we also had several different presenters and use cases still in RxJava. We also had several presenters that could use the same usecase because this is where our business logic is
We needed to balance the amount of time we had for refactoring and still remain on top of deliveries so the hybrid approach worked well for us
During the transition, we had presenters and usecases still using Rx and when the usecases called the suspend function, it was done in a runBlocking
block. This allowed the usecases to continue returning an Rx object as usual and not become a suspend functiongildor
07/02/2024, 1:15 PMPascal How
07/02/2024, 4:34 PMkotlinx-coroutines-rx2
library. This allowed us to wrap suspend functions in rxSingle
for example.
Looking back at some old code, I realise that in several cases, we also had functions returning regular objects (none Rx) and internally they were calling suspend function e.g.
fun someFunction(): MyObject {
runBlocking {
object.sustendFunction()
}
}
If we hadn’t used runBlocking, we would need to convert all the functions down the line to suspend functions and launch a coroutine in the presenter.
In some cases it was alright but sometimes the MyObject
could be used by several other Presenters and classesPascal How
07/02/2024, 4:34 PMMyObject
example was an Identity
object which was required by several method calls 😅