Skip to content

Instantly share code, notes, and snippets.

@Syex Syex/BaseUseCase.kt
Created Jun 12, 2019

Embed
What would you like to do?
abstract class UseCase<out Type, in Params> where Type : Any {
abstract suspend fun run(params: Params): Either<Exception, Type>
suspend operator fun invoke(params: Params, onSuccess: (Type) -> Unit, onFailure: (Exception) -> Unit) {
val result = run(params)
coroutineScope {
launch(uiDispatcher) {
result.fold(
failed = { onFailure(it) },
succeeded = { onSuccess(it) }
)
}
}
}
object None
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.