android10 / android10/Android-CleanArchitecture-Kotlin

UseCase.run returning multiple values?

Abierto
#15 12 comentarios 0 reacciones 0 asignados Ver en GitHub
discussion question
Lenguaje dominante
Kotlin
Estrellas
4.8k
Forks
929
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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?

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.