with
infix fun with(forward: suspend StatefulStepScope<R, S>.(C) -> StepOutcome<R>): StatefulSagaStepConfiguration<C, R, S>
Defines the forward action for the step with explicit outcome control.
The action is executed with a StatefulStepScope receiver, providing:
state: Current saga state (read)updateState { }: Update saga stateresult: Previous step's result (null for first step)completes with: Complete step successfullyfails with: Fail step and trigger compensationskip with: Skip remaining steps without compensation
Example:
first call OrderSteps.VALIDATE with { cart ->
if (!cart.valid) fails with FailureReason.INVALID_ORDER
if (cart.alreadyProcessed) skip with SkipReason.ALREADY_PROCESSED
val order = validateOrder(cart)
updateState { it.copy(orderId = order.id) }
completes with order
}Content copied to clipboard