Created
June 12, 2019 09:17
-
-
Save Syex/4bc10c31de0003c4bd3244d65e5990e0 to your computer and use it in GitHub Desktop.
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 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