Last active
May 19, 2019 14:58
-
-
Save cesarferreira/8a70ca9770b8cf20b1852d1b26420dae to your computer and use it in GitHub Desktop.
This file contains hidden or 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 BaseUseCase<out Type, in Params> where Type : Any { | |
abstract suspend fun run(params: Params): Either<Failure, Type> | |
open operator fun invoke( | |
scope: CoroutineScope, | |
params: Params, | |
onResult: (Either<Failure, Type>) -> Unit = {} | |
) { | |
val backgroundJob = scope.async { run(params) } | |
scope.launch { onResult(backgroundJob.await()) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment