Saga Context
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)
}
}Content copied to clipboard
Parameters
C
The type of user-provided context