transaction

open override fun <T> transaction(definition: TransactionDefinition, block: () -> T): T

Runs block with a transaction open, committing when it returns and rolling back when it throws.

Every execute made from this thread while block runs lands on the transaction's session. That binding is per-thread and does not follow work handed to another one: a coroutine launched on a different dispatcher inside block gets a session of its own and a transaction of its own, and the commit here says nothing about it.

block returning normally is what commits, and only a throw rolls back. A failure already caught and turned into a value - by dbResult, say - is no longer a throw, and a transaction that finishes over one commits. transactionResult is what closes that gap for callers in the result style: it is built on this method and turns a returned failure back into the throw this one needs.

Return

Whatever block produced.

Parameters

definition

How the transaction should be run.

block

The work to run inside it.