StatefulStepScope

class StatefulStepScope<R, S>(stateHolder: AtomicReference<S>, val result: R?)

Scope for forward step execution, providing access to saga state.

This scope is the receiver for forward action lambdas, enabling:

  • Reading current state via state property

  • Updating state via updateState function

  • Accessing previous step's result via result property

Example

first `do` "take-payment" with { cart ->
// Read current state
val currentAmount = state.paymentAmount

// Update state
updateState { it.copy(paymentAmount = payment.amount) }

// Access previous result (null for first step)
val previousOrder = result

createOrder(cart)
}

Parameters

R

The type of result produced by saga steps

S

The type of shared saga state

Constructors

Link copied to clipboard
constructor(stateHolder: AtomicReference<S>, result: R?)

Properties

Link copied to clipboard

DSL builder for completing the step successfully.

Link copied to clipboard

DSL builder for failing the step and triggering compensation.

Link copied to clipboard
val result: R?

Result from the previous step (null for the first step)

Link copied to clipboard

DSL builder for skipping remaining steps without compensation.

Link copied to clipboard
val state: S

Current saga state.

Functions

Link copied to clipboard
fun updateState(transform: (S) -> S): S

Updates the saga state atomically.