otherwise
infix fun otherwise(compensation: suspend CompensationScope<R, S>.() -> Unit): StatefulSagaStepConfiguration<C, R, S>
Defines compensation logic with fluent "otherwise { ... }" syntax.
This is the preferred alternative to "and undo" that enables clean chaining without intermediate variables.
The compensation has access to both result and state for smart compensation.
Example:
first call "take-payment" with { cart ->
updateState { it.copy(paymentAmount = payment.amount) }
createTransaction(cart, payment)
} otherwise {
when {
state.escrowCaptured -> cashManager.dispenseCashRefund(state.paymentAmount)
state.paymentAmount > 0 -> cashManager.returnEscrow()
else -> cashManager.disableAcceptors()
}
}Content copied to clipboard