execute

open suspend override fun <T> execute(block: suspend () -> T): T

Executes a given suspending block of code according to the hedging policy.

This function launches multiple parallel executions (attempts) of the block. A configurable stagger delay can be applied between the start of each subsequent execution.

The result of the first execution to complete successfully is returned immediately. All other concurrent executions are then canceled to conserve resources.

If an execution fails, the policy will wait for other executions to complete. If all executions fail, the exception from the first failing execution is re-thrown.

Return

The result of the first successful execution of the block.

Parameters

block

The suspending block of code to execute.

Type Parameters

T

The return type of the suspending block.

Throws

if all executions fail, the exception from the first failure is thrown.