pub struct CircuitBreaker { /* private fields */ }Expand description
A thread-safe circuit breaker. Usage: before_call -> do
work -> record_success /
record_failure /
record_abort.
Implementations§
Source§impl CircuitBreaker
impl CircuitBreaker
Sourcepub fn new(
config: BreakerConfig,
clock: Option<Arc<dyn Clock>>,
on_state_change: Option<Box<dyn Fn(BreakerState, BreakerState) + Send + Sync>>,
) -> Self
pub fn new( config: BreakerConfig, clock: Option<Arc<dyn Clock>>, on_state_change: Option<Box<dyn Fn(BreakerState, BreakerState) + Send + Sync>>, ) -> Self
Builds a breaker. clock defaults to SystemClock when None.
Sourcepub fn state(&self) -> BreakerState
pub fn state(&self) -> BreakerState
The current state, refreshing Open -> HalfOpen if the recovery timeout elapsed.
Sourcepub fn before_call(&self) -> Result<(), PoolError>
pub fn before_call(&self) -> Result<(), PoolError>
Returns PoolError::CircuitOpen if the call must not be attempted.
Sourcepub fn record_success(&self)
pub fn record_success(&self)
Records a successful call.
Sourcepub fn record_failure(&self)
pub fn record_failure(&self)
Records a failed call.
Sourcepub fn record_abort(&self)
pub fn record_abort(&self)
Releases a half-open probe slot without counting it either way (the call was cancelled or timed out before the backend answered).
Auto Trait Implementations§
impl !Freeze for CircuitBreaker
impl !RefUnwindSafe for CircuitBreaker
impl !UnwindSafe for CircuitBreaker
impl Send for CircuitBreaker
impl Sync for CircuitBreaker
impl Unpin for CircuitBreaker
impl UnsafeUnpin for CircuitBreaker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more