Mattia Pagini
08/02/2021, 4:27 PMscope.launch {
//errors are propagated with resumeWithException
try {
library.step1()
library.step2()
val result3 = library.step3()
library.step4(result3)
} catch (error: ResultException) {
when (error.code) {
1 -> ....
2 -> ....
3 -> ....
else -> ...
}
}
}
scope.launch {
//errors are handled as state, propagated with resumeWith
val result1 = library.step1()
if (result1 is Result.Success) {
val result2 = library.step2()
if (result2 is Result.Success) {
val result3 = library.step3()
if (result3 is Result.Success) {
library.step4(result3)
} else {
//handle error
}
} else {
//handle error
}
} else {
//handle error
}
}