compensate

open infix fun compensate(compensate: suspend (A) -> Unit): Saga<A>

Add a compensating action to a Saga. A single Saga can have many compensating actions, they will be composed in a FILO order. This makes sure they're executed in reverse order as the actions.

saga {
saga { println("A") }.compensate { println("A - 1") }
.compensate { println("A - 2") }
.bind
throw RuntimeException("Boom!")
}.transact()
// A - 2
// A - 1
// RuntimeException("Boom!")

Sources

jvm source
Link copied to clipboard