Trait failsafe::CircuitBreaker

source ·
pub trait CircuitBreaker {
    // Required methods
    fn is_call_permitted(&self) -> bool;
    fn call_with<P, F, E, R>(&self, predicate: P, f: F) -> Result<R, Error<E>>
       where P: FailurePredicate<E>,
             F: FnOnce() -> Result<R, E>;

    // Provided method
    fn call<F, E, R>(&self, f: F) -> Result<R, Error<E>>
       where F: FnOnce() -> Result<R, E> { ... }
}
Expand description

A circuit breaker’s public interface.

Required Methods§

source

fn is_call_permitted(&self) -> bool

Requests permission to call.

It returns true if a call is allowed, or false if prohibited.

source

fn call_with<P, F, E, R>(&self, predicate: P, f: F) -> Result<R, Error<E>>
where P: FailurePredicate<E>, F: FnOnce() -> Result<R, E>,

Executes a given function within circuit breaker.

Depending on function result value, the call will be recorded as success or failure. It checks error by the provided predicate. If the predicate returns true for the error, the call is recorded as failure otherwise considered this error as a success.

Provided Methods§

source

fn call<F, E, R>(&self, f: F) -> Result<R, Error<E>>
where F: FnOnce() -> Result<R, E>,

Executes a given function within circuit breaker.

Depending on function result value, the call will be recorded as success or failure.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<POLICY, INSTRUMENT> CircuitBreaker for StateMachine<POLICY, INSTRUMENT>
where POLICY: FailurePolicy, INSTRUMENT: Instrument,