vertx / io.vertx.reactivex.circuitbreaker / CircuitBreaker / executeWithFallback

executeWithFallback

open fun <T : Any> executeWithFallback(command: Handler<Future<T>>, fallback: Function<Throwable, T>): Future<T>

Executes the given operation with the circuit breaker control. The operation is generally calling an external system. The operation receives a object as parameter and must call when the operation has terminated successfully. The operation must also call in case of failure.

The operation is not invoked if the circuit breaker is open, and the given fallback is called immediately. The circuit breaker also monitor the completion of the operation before a configure timeout. The operation is considered as failed if it does not terminate in time.

This method returns a object to retrieve the status and result of the operation, with the status being a success or a failure. If the fallback is called, the returned future is successfully completed with the value returned from the fallback. If the fallback throws an exception, the returned future is marked as failed.

Parameters

command - the operation

fallback - the fallback function. It gets an exception as parameter and returns the fallback result

Return
a future object completed when the operation or its fallback completes