I would like to modify the default Flow.catch function and always call a specific suspend function logOutIfUserHasNoAccount()
. My current implementation is:
private suspend fun <T> Flow<T>.catchLoginError(action: suspend FlowCollector<T>.(Throwable) -> Unit): Flow<T> {
logOutIfUserHasNoAccount()
return catch(action)
}
My questions is: Is there any disadvantage that my Flow.catchLoginError function is also a suspend function? The default implementation of catch is:
// Not suspending
public fun <T> Flow<T>.catch(action: suspend FlowCollector<T>.(Throwable) -> Unit): Flow<T> { /* compiled code */ }
Using
suspend fun login() = flow {
}.catchLoginError( e ->
// here it should call "logOufIfUserHasNoAccount" first
doStuff(e)
}