doSuspendTransaction
suspend fun <T> doSuspendTransaction( onRollbackStepError: suspend (Throwable) -> Unit = { }, block: suspend TransactionsDSL.() -> T): Result<T>(source)
Starts transaction with opportunity to add actions rollableBackOperation. How to use:
doSuspendTransaction {
println("start of action")
withRollback({ // it - result of action
// some rollback action
}) {
// Some action with rollback
}
withRollback({
repository.delete(it) // it - result of createSomething, if it completes successfully
}) {
repository.createSomething()
}
withRollback({
// will not be triggered due to error in action
}) {
error("It is just a simple error") // Will trigger rolling back previously successfully completed actions
}
}
Content copied to clipboard
Parameters
onRollbackStepError
Will be called if rollback action throwing some error