May be, I should explain what I’m trying… :) ```fu...
# arrow
s
May be, I should explain what I’m trying… :)
Copy code
fun <A> runInTransaction(client: CoroutineClient, action: (ClientSession) -> IO<A>): IO<A> {

    return IO.effect {
        val session = client.startSession()
        session.startTransaction()
        session
    }.bracketCase(
        release = { clientSession, case ->
            IO {
                when (case) {
                    ExitCase.Completed -> clientSession.commitTransaction().awaitFirstOrNull()
                    else -> clientSession.abortTransaction().awaitFirstOrNull()
                }
                clientSession.close()
            }
        },
        use = action
    )
}
I’m trying to run an action in a transaction and act upon the result. So far, so fine. But I would like to indicate an error if the transaction failed.