Jorge Castillo
03/02/2020, 11:07 AMlaunchOnXX
DSL but over IO functions.
fun sideEffect(): IO<Error, Unit> = TODO()
// Overload to use uniflow dispatchers and get automatic cancellation of the IO task when the scope gets cancelled.
fun <E> CoroutineScope.launchOnIO(
block: IO<E, Unit>,
callback: (IOResult<E, Unit>) -> Unit
) =
launch(<http://UniFlowDispatcher.dispatcher.io|UniFlowDispatcher.dispatcher.io>()) {
block.unsafeRunScoped(this, callback)
}
So you can call it like:
scope.launchOnIO(sideEffect()) { cb ->
cb.fold(
ifException = { TODO() },
ifLeft = { TODO() },
ifSuccess = { TODO() }
)
}