Android-CleanArchitecture-Kotlin
Android-CleanArchitecture-Kotlin copied to clipboard
How to run usecases in parallel?
I learned a lot by reading this architecture. But in my real life project, viewmodel needs to run 2 or more usecases in prallel and join the result to update the ui. With coroutine in my current code, my code is like this
val job1 = async {usecase A}
val job2 = async {usecase B}
processResults(job1.await(),job2.await()) // This combine two result and do some calculation here
However, For Either class with either() method, I don't know how to achieve this.
There is a map method at the bottom of Either class , looks like a solution for this issue.
I remove CoroutineScope in UseCase, and add to the BaseViewModel to reach the parallel run.
Hi @Nyan274 do you found the solution?
Looking for a solution
Each use case is already in a separate thread. Why not inject the 2 use cases in your view model and run them asynchronously? You can then incorporate rx kotlin / rxjava or even coroutines to join the results