pub struct CircuitBreaker { /* private fields */ }Expand description
Gates access to a flaky resource: trips after failure_threshold
consecutive unresponsive reports, stays open for a fixed cooldown, then
admits exactly one probe request to test recovery.
Each clock-dependent method has an _at(now: Instant) form (the real
logic) plus a wrapper that passes Instant::now(), so the state machine
is unit-testable with a synthetic clock and no sleeps.
Implementations§
Source§impl CircuitBreaker
impl CircuitBreaker
pub fn new(config: CircuitBreakerConfig) -> CircuitBreaker
pub fn admit(&self) -> Admission
pub fn admit_at(&self, now: Instant) -> Admission
Sourcepub fn admit_bypass_only(&self) -> Admission
pub fn admit_bypass_only(&self) -> Admission
Same read of state as admit, but never returns Probe and never
mutates open_until — for a caller (prefetch) that must not be able
to consume the single per-cooldown probe slot a demand read would
otherwise receive.
Sourcepub fn record_responsive(&self) -> Transition
pub fn record_responsive(&self) -> Transition
The resource completed an operation (any HTTP status counts — it’s alive).
pub fn record_responsive_at(&self, _now: Instant) -> Transition
Sourcepub fn record_unresponsive(&self) -> Transition
pub fn record_unresponsive(&self) -> Transition
The resource lost: an abandon-budget expiry, a stall, a connect failure, or a transport error (see “Abandon vs. unresponsive”).
pub fn record_unresponsive_at(&self, now: Instant) -> Transition
Trait Implementations§
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].