Expand description
Futures aware circuit breaker.
Example
Using default backoff strategy and failure accrual policy.
use futures::{future, Future};
use failsafe::Config;
use failsafe::futures::CircuitBreaker;
// A function that sometimes failed.
fn dangerous_call() -> impl Future<Item = (), Error = ()> {
future::lazy(|| {
if thread_rng().gen_range(0, 2) == 0 {
return Err(())
}
Ok(())
})
}
// Create a circuit breaker which configured by reasonable default backoff and
// failure accrual policy.
let circuit_breaker = Config::new().build();
// Wraps `dangerous_call` result future within circuit breaker.
let future = circuit_breaker.call(dangerous_call());
let result = future.wait();
Structs
A circuit breaker’s future.
Traits
A futures aware circuit breaker’s public interface.