Skip to content

Instantly share code, notes, and snippets.

@cesarferreira
Last active May 19, 2019 14:58
Show Gist options
  • Save cesarferreira/8a70ca9770b8cf20b1852d1b26420dae to your computer and use it in GitHub Desktop.
Save cesarferreira/8a70ca9770b8cf20b1852d1b26420dae to your computer and use it in GitHub Desktop.
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