-
-
Save aleweichandt/aaf0d82dfdd4f8ca6a5f878760d32640 to your computer and use it in GitHub Desktop.
Flow UseCase abstraction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class FlowUseCase<in TParam, out TResult>( | |
private val exceptionHandler: IExceptionHandler, | |
private val dispatcher: CoroutineDispatcher | |
) { | |
@ExperimentalCoroutinesApi | |
@Suppress("TooGenericExceptionCaught") | |
suspend operator fun invoke(param: TParam) = | |
performAction(param) | |
.catch { exception -> | |
exceptionHandler.handle(exception) | |
emit(Result.Failure(exception)) | |
} | |
.flowOn(dispatcher) | |
protected abstract suspend fun performAction(param: TParam): Flow<Result<TResult>> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment