Android-CleanArchitecture-Kotlin icon indicating copy to clipboard operation
Android-CleanArchitecture-Kotlin copied to clipboard

How to run usecases in parallel?

Open Nyan274 opened this issue 7 years ago • 5 comments

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.

Nyan274 avatar Jun 30 '18 10:06 Nyan274

There is a map method at the bottom of Either class , looks like a solution for this issue.

jovanovic-filip avatar Sep 12 '18 03:09 jovanovic-filip

I remove CoroutineScope in UseCase, and add to the BaseViewModel to reach the parallel run.

jasonni avatar Dec 18 '18 10:12 jasonni

Hi @Nyan274 do you found the solution?

azisuazusa avatar Feb 27 '19 10:02 azisuazusa

Looking for a solution

multlurk avatar Apr 09 '19 15:04 multlurk

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

crjacinro avatar Apr 09 '19 15:04 crjacinro