Package-level declarations

Types

Link copied to clipboard

Marker interface for user-defined typed compensation actions.

Link copied to clipboard
class CompensationScope<R, S>(val result: R, val state: S)

Scope for compensation execution, providing access to both step result and saga state.

Link copied to clipboard

Builder for "completes with result" DSL syntax.

Link copied to clipboard
class EventWatcher<C, R>(builder: SagaBuilder<C, R>)

Wrapper for the "events" keyword in monitor configuration.

Link copied to clipboard

Builder for "fails with reason" DSL syntax.

Link copied to clipboard
class FlowBasedSagaExecutor<C, R>(delegate: SagaExecutor<C, R>) : SagaExecutor<C, R>

Flow-based saga executor that emits events as a reactive stream.

Link copied to clipboard

Marker for steps that are safe to retry (idempotent operations).

Link copied to clipboard
data class IdempotentStep<C, R>(val step: SagaStep<C, R>, val idempotent: Boolean = true)

Extension to mark steps as idempotent at runtime.

Link copied to clipboard

Default no-op monitor implementation.

Link copied to clipboard
data class RetryPolicy(val maxAttempts: Int = 3, val initialDelay: Duration = 100.milliseconds, val maxDelay: Duration = 10.seconds, val multiplier: Double = 2.0, val jitter: Double = 0.1, val retryOn: (Throwable) -> Boolean = { true })

Retry policy for saga step execution with exponential backoff.

Link copied to clipboard
class SagaBuilder<C, R>

DSL builder for creating standalone saga executors.

Link copied to clipboard
data class SagaContext<out C>(val userContext: C, val executionId: String = generateExecutionId(), val startTime: Long = System.currentTimeMillis())

Context carried through saga execution.

Link copied to clipboard
class SagaDoStarter<C, R>(builder: SagaBuilder<C, R>, isFirst: Boolean)

Wrapper for the "do" keyword in saga step configuration.

Link copied to clipboard
sealed interface SagaEvent

Events emitted during saga execution for monitoring and logging.

Link copied to clipboard
data class SagaExecutionError(val step: TypedValue, val phase: SagaExecutionError.Phase, val exception: Throwable, val timestamp: Long = System.currentTimeMillis())

Error that occurred during saga execution or compensation.

Link copied to clipboard
interface SagaExecutor<C, R>

Executes saga steps with forward and compensating logic.

Link copied to clipboard
fun interface SagaMonitor

Monitor for observing saga execution lifecycle events.

Link copied to clipboard
sealed interface SagaResult<out R>

Result of saga execution.

Link copied to clipboard
data class SagaStep<C, R>(val step: TypedValue, val forward: suspend (C) -> R, val compensation: suspend (R) -> Unit? = null, val idempotent: Boolean = false, val timeout: Duration? = null, val retryPolicy: RetryPolicy? = null)

Immutable descriptor of a saga step with forward and compensation logic.

Link copied to clipboard
class SagaStepConfiguration<C, R>(builder: SagaBuilder<C, R>)

Configuration scope for a saga step, enabling fluent chaining.

Link copied to clipboard
class SagaStepWithBuilder<C, R>(builder: SagaBuilder<C, R>, step: TypedValue)

Wrapper for the "with" keyword in step forward action configuration.

Link copied to clipboard

Builder for "skip with reason" DSL syntax.

Link copied to clipboard
class StatefulEventWatcher<C, R, S : Any>(builder: StatefulSagaBuilder<C, R, S>)

Wrapper for the "events" keyword in monitor configuration.

Link copied to clipboard
class StatefulSagaBuilder<C, R, S : Any>(initialState: S)

DSL builder for creating stateful saga executors with typed state management.

Link copied to clipboard
class StatefulSagaDoStarter<C, R, S : Any>(builder: StatefulSagaBuilder<C, R, S>, isFirst: Boolean)

Wrapper for the "do" keyword in stateful saga step configuration.

Link copied to clipboard
interface StatefulSagaExecutor<C, R, S>

Executes stateful saga steps with forward and compensating logic.

Link copied to clipboard
sealed interface StatefulSagaResult<out R, out S>

Result of stateful saga execution.

Link copied to clipboard
data class StatefulSagaStep<C, R, S>(val step: TypedValue, val forward: suspend StatefulStepScope<R, S>.(C) -> StepOutcome<R>, val compensation: suspend CompensationScope<R, S>.() -> Unit? = null, val idempotent: Boolean = false, val timeout: Duration? = null, val retryPolicy: RetryPolicy? = null)

Represents a single step in a stateful saga with typed state management.

Link copied to clipboard

Configuration scope for a stateful saga step, enabling fluent chaining.

Link copied to clipboard

Wrapper for the "with" keyword in stateful step forward action configuration.

Link copied to clipboard

Builder for step action configuration.

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

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

Link copied to clipboard
class StepActionBuilder<C, R>(builder: SagaBuilder<C, R>, step: TypedValue)

Builder for step action configuration.

Link copied to clipboard
class StepFailedException(val failureReason: TypedValue) : Exception

Exception thrown when a step explicitly fails using fails with reason.

Link copied to clipboard
sealed interface StepOutcome<out R>

Represents the outcome of a saga step execution.

Link copied to clipboard
sealed class TypedValue

A type-safe wrapper for values that may be either enums or strings.

Properties

Link copied to clipboard

Starts the first saga step with "first do 'name' with { ... }" syntax.

Link copied to clipboard

Alternative: starts any saga step (not necessarily first).

Link copied to clipboard

Starts monitor configuration with "watching" keyword.

Functions

Link copied to clipboard

Extension to allow chaining after SagaStepConfiguration.

Extension to allow chaining after StatefulSagaStepConfiguration.

Link copied to clipboard

Extension function to convert a SagaExecutor to a FlowBasedSagaExecutor.

Link copied to clipboard

Marks the last step as idempotent using simple syntax.

Link copied to clipboard

Marks the last step as non-idempotent.

Link copied to clipboard
infix fun <C, R> SagaBuilder<C, R>.compensateWith(compensation: suspend (R) -> Unit): SagaBuilder<C, R>

Adds compensation to the last defined step using simple syntax (suspend function).

infix fun <C, R, S : Any> StatefulSagaBuilder<C, R, S>.compensateWith(compensation: suspend CompensationScope<R, S>.() -> Unit): StatefulSagaBuilder<C, R, S>

Adds compensation to the last defined step using simple syntax.

Link copied to clipboard
fun <C, R> SagaExecutor<C, R>.executeToFlow(context: C, coroutineContext: CoroutineContext = EmptyCoroutineContext, timeout: Duration? = null): Flow<SagaEvent>

Execute saga and return a Flow that emits all events followed by a terminal result event.

Link copied to clipboard
infix fun <C, R> SagaBuilder<C, R>.monitoring(handler: (SagaEvent) -> Unit)
infix fun <C, R, S : Any> StatefulSagaBuilder<C, R, S>.monitoring(handler: (SagaEvent) -> Unit)

Adds a saga monitor using "monitoring with" syntax.

Link copied to clipboard
infix fun <C, R> SagaBuilder<C, R>.monitorWith(monitor: SagaMonitor)
infix fun <C, R, S : Any> StatefulSagaBuilder<C, R, S>.monitorWith(monitor: SagaMonitor)

Adds a saga monitor instance.

Link copied to clipboard
suspend fun <R> parallelOps(vararg operations: suspend () -> R): List<R>

Execute multiple suspend operations in parallel and wait for all to complete.

Link copied to clipboard
suspend fun <R1, R2> parallelPair(op1: suspend () -> R1, op2: suspend () -> R2): Pair<R1, R2>

Execute two operations in parallel and return their results as a Pair.

Link copied to clipboard
suspend fun <R1, R2, R3> parallelTriple(op1: suspend () -> R1, op2: suspend () -> R2, op3: suspend () -> R3): Triple<R1, R2, R3>

Execute three operations in parallel and return their results as a Triple.

Link copied to clipboard
fun <C, R> sagaExecutor(configure: SagaBuilder<C, R>.() -> Unit): SagaExecutor<C, R>

Factory function for creating sagas with DSL.

fun <C, R, S : Any> sagaExecutor(initialState: S, configure: StatefulSagaBuilder<C, R, S>.() -> Unit): StatefulSagaExecutor<C, R, S>

Factory function for creating stateful sagas with typed state management.

Link copied to clipboard
infix fun <C, R> SagaBuilder<C, R>.step(name: String): StepActionBuilder<C, R>

Alternative syntax: "step 'name' does { ... }"

Link copied to clipboard
suspend fun <T> withRetry(policy: RetryPolicy, operation: suspend () -> T): T

Execute an operation with retry logic according to the policy.