execute

abstract suspend fun <T> execute(block: suspend () -> T): T

Executes the provided suspendable block of code under the control of the composed resilience policies.

The policies are applied in a specific order, wrapping the execution of the block. The execution order from the outermost to the innermost policy is as follows:

Execution Order (Outer → Inner):

  1. Timeout: Enforces an overall time limit for the entire operation, including all retries.

  2. Retry: Retries the execution if it fails, subject to the retry policy's conditions.

  3. Circuit Breaker: Prevents execution if the circuit is open, failing fast.

  4. Rate Limiter: Delays execution until a permit is available from the rate limiter.

  5. Bulkhead: Restricts concurrent executions, queueing or rejecting if the limit is reached.

  6. Hedging: May trigger secondary, hedged executions if the primary one is slow.

  7. Block: The actual suspendable operation to be executed.

Return

The result of the block if it completes successfully.

Parameters

block

The suspendable lambda function to execute.

Type Parameters

T

The return type of the block.

Throws

if the execution fails after all policies have been applied (e.g., all retries failed, or the timeout was exceeded).