SagaResult

sealed interface SagaResult<out R>

Result of saga execution.

This sealed interface provides type-safe handling of saga execution outcomes, ensuring that all possible results are explicitly handled by the caller.

Result Types

  • Completed - Saga completed successfully with a result value

  • Aborted - Saga aborted due to step failure, all compensations succeeded

  • CompensationFailure - Saga aborted and compensation failed (critical failure)

Usage Example

val result = saga.execute(context)
when (result) {
is SagaResult.Completed -> {
// All steps succeeded
processResult(result.value)
}
is SagaResult.Aborted -> {
// A step failed but all compensations succeeded
logError(result.error)
notifyUser("Transaction cancelled")
}
is SagaResult.CompensationFailure -> {
// Critical failure - manual intervention may be required
alertOps(result.originalError, result.compensationErrors)
}
}

Parameters

R

The result type on successful completion

Inheritors

Types

Link copied to clipboard
data class Aborted(val error: SagaExecutionError) : SagaResult<Nothing>

Saga aborted due to step failure.

Link copied to clipboard
data class CompensationFailure(val originalError: SagaExecutionError, val compensationErrors: List<SagaExecutionError>) : SagaResult<Nothing>

Saga aborted and compensation failed.

Link copied to clipboard
data class Completed<R>(val value: R) : SagaResult<R>

Saga completed successfully with result.