SagaContext

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

Context carried through saga execution.

Wraps user-provided context with execution metadata such as execution ID and start time. This allows saga infrastructure to track execution while keeping user context clean.

Thread Safety

Execution ID generation is thread-safe and can be used concurrently from multiple coroutines without risk of ID collisions.

Usage

SagaContext is created automatically by the saga executor and is primarily used internally. Users work with their own context types directly.

data class OrderContext(val orderId: String, val items: List<String>)

val saga = sagaExecutor<OrderContext, OrderResult> {
step("reserve") { context ->
// context is OrderContext, not SagaContext
inventoryService.reserve(context.items)
}
}

Parameters

C

The type of user-provided context

Constructors

Link copied to clipboard
constructor(userContext: C, executionId: String = generateExecutionId(), startTime: Long = System.currentTimeMillis())

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Unique identifier for this saga execution

Link copied to clipboard

Timestamp when saga execution started (milliseconds since epoch)

Link copied to clipboard

The user-provided context object