Hi, based on class Result I create class ResultAsy...
# coroutines
d
Hi, based on class Result I create class ResultAsync to encapsulate Coroutines results, what do you think about?
u
Did you try using
runCatching
? https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/run-catching.html You can use it as below:
Copy code
//In your class that extends CoroutineScope
fun getUser() {
    launch {
        runCatching { userRepository.getUser() }
            .onSuccess { /**/ }
            .onFailure { /**/ }
    }
}
d
I know is possible with this way, but is necessary use launch block always, and I am a little lazy 😅
However if in your application you have a default error handler that return a friendly error you can implements in this method and you always will have a friendly error on onFailure
u
Yeah, I just feel you. 😄 > necessary use launch block always. I meant that probably you can use
runCatching
to replace
ResultAsync<T>
(in your gists) to
Result<T>
.