pub struct DefaultCircuitBreaker { /* private fields */ }Expand description
Unstable (feature: circuit-breaker) — may change or be removed
SDK reference implementation: threshold-based with half-open state machine.
The thresholds (failure_threshold, reset_timeout) are SDK-illustrative,
not consumer policy. A consumer whose traffic profile differs (e.g. A2A
with 12 failures/min and a 30s recovery window) implements
CircuitBreaker for its own struct rather than reusing this.
Implementations§
Source§impl DefaultCircuitBreaker
impl DefaultCircuitBreaker
Sourcepub fn new(
failure_threshold: u32,
reset_timeout: Duration,
) -> DefaultCircuitBreaker
pub fn new( failure_threshold: u32, reset_timeout: Duration, ) -> DefaultCircuitBreaker
Construct a new breaker. failure_threshold is the number of
consecutive failures that trip the breaker; reset_timeout is how
long the breaker stays open before allowing a trial call (half-open).
Sourcepub fn state(&self) -> BreakerState
pub fn state(&self) -> BreakerState
Current state (testing/observability).
Sourcepub fn failure_count(&self) -> u32
pub fn failure_count(&self) -> u32
Failure count since the last successful call (observability).
Trait Implementations§
Source§impl CircuitBreaker for DefaultCircuitBreaker
impl CircuitBreaker for DefaultCircuitBreaker
Source§fn check(&self) -> Result<(), BreakerError>
fn check(&self) -> Result<(), BreakerError>
Returns
Err(BreakerError::Open) if the circuit is open (calls should
fail-fast). The check is cheap (atomic load) so callers may invoke it
before every retry.Source§fn record_success(&self)
fn record_success(&self)
Record a successful call. Resets the failure count and, if the breaker
was in
HalfOpen, returns it to Closed.Source§fn record_failure(&self)
fn record_failure(&self)
Record a failed call. Increments the failure count; if the count
reaches the configured threshold the breaker trips to
Open.Auto Trait Implementations§
impl !Freeze for DefaultCircuitBreaker
impl RefUnwindSafe for DefaultCircuitBreaker
impl Send for DefaultCircuitBreaker
impl Sync for DefaultCircuitBreaker
impl Unpin for DefaultCircuitBreaker
impl UnsafeUnpin for DefaultCircuitBreaker
impl UnwindSafe for DefaultCircuitBreaker
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