Open mattognibene opened 5 years ago
I have a number of notes and I figure I'll just add them as an overall comment as opposed to several smaller comments:
suspend
function.Result
class. I feel like there could a number of problems with this; the main one being that this clashes with kotlin.Result
.backgroundJob
confuses a lot of coroutine terminology. The async
function returns a Deferred
object which is more like a future/promise.My personal opinions on it are this you either lean into this having a suspend
function that's exposed or hide everything behind the data layer and a custom callback. The latter option sort of defeats the purpose of this being called a CoroutineUseCase
at all though.
Example 1:
interface CoroutineUseCase<T, R> {
suspend fun executeCoroutine(params: T): R
}
Example 2:
abstract class CallbackUseCase<T, R> : BaseUseCase<T, R>() {
fun executeCallback(params: T, callback: Callback<R>) {
try {
callback.onSuccess(execute(params))
} catch (e: Exception) {
callback.onFailure(e)
}
}
}
interface Callback<R> {
fun onSuccess(result: R)
fun onFailure(error: Throwable)
}
Edit: the second example will obviously need to add logic to handle threading.
CoroutineUseCase