pub struct CircuitBreaker { /* private fields */ }Expand description
Lightweight, lock-free per-proxy circuit breaker.
All fields are atomics so many tasks can call record_failure /
record_success / is_available concurrently without a mutex.
Implementations§
Source§impl CircuitBreaker
impl CircuitBreaker
Sourcepub const fn new(threshold: u32, half_open_after_ms: u64) -> Self
pub const fn new(threshold: u32, half_open_after_ms: u64) -> Self
Create a new breaker from config parameters.
Sourcepub fn is_available(&self) -> bool
pub fn is_available(&self) -> bool
Returns true when the proxy may be used (Closed or HalfOpen).
When the circuit is Open and enough time has elapsed since the last
failure the breaker transitions to HalfOpen and returns true.
Sourcepub fn record_success(&self)
pub fn record_success(&self)
Record a successful request.
When the circuit is in HalfOpen this resets the failure count and
transitions back to Closed.
Sourcepub fn record_failure(&self)
pub fn record_failure(&self)
Record a failed request.
In Closed: if the incremented count reaches the threshold the circuit
trips to Open. In HalfOpen: immediately trips back to Open and resets
the timer.
Auto Trait Implementations§
impl !Freeze for CircuitBreaker
impl RefUnwindSafe for CircuitBreaker
impl Send for CircuitBreaker
impl Sync for CircuitBreaker
impl Unpin for CircuitBreaker
impl UnsafeUnpin for CircuitBreaker
impl UnwindSafe 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