Satyam Agarwal
09/11/2020, 8:58 PMIO<A>
to suspend -> Either<Throwable, A>
, is this correct :
fun Ds.closeTxn(exitCase: ExitCase<Throwable>): IO<Unit> {
return IO {
when (exitCase) {
is ExitCase.Cancelled -> this.rollback().close()
is ExitCase.Completed -> this.commit().close()
is ExitCase.Error -> this.rollback().close()
}
}.guarantee(IO { this.close() })
}
to
suspend fun Ds.closeTxn(e: arrow.fx.coroutines.ExitCase): Either<Throwable, Unit> {
return guarantee(
{
Either.catch {
when (e) {
is arrow.fx.coroutines.ExitCase.Completed -> this.commit().close()
is arrow.fx.coroutines.ExitCase.Cancelled -> this.rollback().close()
is arrow.fx.coroutines.ExitCase.Failure -> this.rollback().close()
}
}
},
{ Either.catch { this.close() } }
)
}
raulraja
09/11/2020, 10:57 PMraulraja
09/11/2020, 10:58 PMraulraja
09/11/2020, 10:59 PM