execute

abstract suspend fun execute(context: C): SagaResult<R>

Execute the saga with the given context.

Executes all saga steps sequentially using suspend functions. If any step fails, previously completed steps are compensated in reverse order (LIFO).

This is a suspend function and must be called from a coroutine.

Return

SagaResult indicating success, abort, or compensation failure

Parameters

context

The context to pass to saga steps


abstract suspend fun execute(context: C, coroutineContext: CoroutineContext = EmptyCoroutineContext, timeout: Duration? = null): SagaResult<R>

Execute the saga with the given context, coroutine context, and optional timeout.

Executes all saga steps sequentially using suspend functions with the provided coroutine context. If any step fails, previously completed steps are compensated in reverse order (LIFO).

CoroutineContext Propagation

The provided coroutineContext is merged with the current context and used for all saga operations, including step execution, compensation, and monitoring.

Timeout Handling

If a timeout is specified, the entire saga execution must complete within that duration. If the timeout is exceeded, a TimeoutCancellationException is thrown, completed steps are compensated, and the saga is aborted.

Return

SagaResult indicating success, abort, or compensation failure

Parameters

context

The context to pass to saga steps

coroutineContext

Additional context to use for execution

timeout

Overall saga timeout (null = no timeout)