compensate

fun compensate(compensation: suspend (R) -> Unit): SagaBuilder<C, R>

Define compensation logic for the current step.

The compensation action receives the result from the forward action, allowing it to use information from the successful execution to perform the compensation. For example, if the forward action creates a resource and returns its ID, the compensation can use that ID to delete the resource.

The compensation action is a suspend function, allowing for async operations.

Must be called after step().

Return

This builder for method chaining

Parameters

compensation

Suspend function that compensates (undoes) the step

Throws

if called before step()