Skip to main content

Module circuit_breaker

Module circuit_breaker 

Source
Expand description

Circuit breaker.

Three states:

  • Closed — calls go through; consecutive failures are counted. When the count hits failure_threshold, the breaker trips to Open.
  • Open — calls are rejected with ToolkitError::CircuitOpen until cool_down has elapsed since the trip. Then the breaker moves to HalfOpen.
  • HalfOpen — only half_open_max_calls calls are admitted. If they all succeed, the breaker returns to Closed. A single failure trips it back to Open.

The implementation deliberately uses a single Mutex for the state machine. Breakers protect expensive downstream calls — the cost of locking is dwarfed by the network/IO cost of the call itself.

Structs§

CircuitBreaker
A circuit breaker. Cheap to clone; the inner state is Arc<Mutex<_>>.
CircuitBreakerBuilder
Builder for CircuitBreaker.

Enums§

CircuitState
Current state of the breaker.