execute To Flow
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.
This is an alternative API that returns a cold Flow containing all saga events. The flow completes when the saga execution finishes.
Usage Example
val executor = sagaExecutor<Ctx, Result> { /* ... */}
executor.executeToFlow(context).collect { event ->
when (event) {
is SagaEvent.SagaCompleted -> println("Success: ${event.result}")
is SagaEvent.SagaAborted -> println("Failed: ${event.error}")
else -> println("Event: $event")
}
}Content copied to clipboard
Return
Flow of saga events including a terminal event
Parameters
context
The saga context
coroutine Context
Optional coroutine context for execution
timeout
Optional timeout for the entire saga