pub struct CircuitBreaker { /* private fields */ }Expand description
Thread-safe three-state circuit breaker.
Implementations§
Source§impl CircuitBreaker
impl CircuitBreaker
Sourcepub fn new(config: CircuitBreakerConfig) -> CircuitBreaker
pub fn new(config: CircuitBreakerConfig) -> CircuitBreaker
Create a new breaker with the given configuration and the default
(TokioClock) clock.
Sourcepub fn with_clock(
config: CircuitBreakerConfig,
clock: Arc<dyn Clock>,
) -> CircuitBreaker
pub fn with_clock( config: CircuitBreakerConfig, clock: Arc<dyn Clock>, ) -> CircuitBreaker
Create a breaker with a custom clock (primarily for tests).
Sourcepub fn config(&self) -> &CircuitBreakerConfig
pub fn config(&self) -> &CircuitBreakerConfig
Current configuration.
Sourcepub fn current_state(&self) -> CircuitState
pub fn current_state(&self) -> CircuitState
Current state. Transitions from Open to HalfOpen happen lazily on observation, so this call also advances state when appropriate.
Sourcepub fn allow_call(&self) -> bool
pub fn allow_call(&self) -> bool
Ask whether a call is currently allowed through. true means the
caller should invoke the downstream service; false means the
breaker is Open and the caller must fail fast.
Sourcepub fn record_success(&self)
pub fn record_success(&self)
Record a successful downstream call.
Sourcepub fn record_failure(&self)
pub fn record_failure(&self)
Record a failed downstream call.
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