android10 / android10/Android-CleanArchitecture-Kotlin
UseCase.run returning multiple values?
- Lingua principale
- Kotlin
- Stelle
- 4.8k
- Fork
- 929
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
I like the approach overall. I have implemented a very similar pattern in my app and has been working fine.
However, there is one use case that I never know how to appropriately model.
I found that the method `UseCase.run` returning a single value might sometimes be restricting functionality and can always not be the best option.
Let me clarify with an example:
- A `UseCase` queries a `Repository` for data.
- The `Repository` queries three different datasources (memory, disk, network) to retrieve results, some of them might not be available (memory not warm, disk doesn't exists, network not available)
- The `View` has to reflect the data as it comes in from the repository.
The problem is that the `UseCase.run` returns a single value, so in the example the `UseCase` will return only when all the datasources in the `Repository` have returned the data.
A simple work-around is to execute the `UseCase` three different times with different parameters that specify which datasource should be query. However, this does not sounds like a good separation of concern, as the `Presenter` will have to specify parameters corresponding to the datasources that need to be queried.
Another alternative (hack) is for the `UseCase.run` to return a `Either>` where `UpdateableType` is similar to an `rx.Observable`. In this case the `UseCase` will return right away, and the `Presenter` will subscribe to data updates as they occur. This also feels ugly, as it will be hard to represent a `Failure` once the `UseCase` has returned.
Another way of solving it this problem that I have recently started to look at, is to use coroutines `Channel`s so the `UseCase` can send multiple values to the `Presenter`s, but i'm not quite there yet to propose a working solution.
What do you think?
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.