How lerouxrgd/recloser works
Project type and purpose
• This is a Rust library crate (recloser) that implements a concurrent circuit-breaker pattern using ring buffers.
• It provides both synchronous (Recloser) and asynchronous (AsyncRecloser) APIs to wrap arbitrary function or future calls, track failure rates, and open/close the circuit based on configurable thresholds and time windows.
File structure
• Top-level files:
• Cargo.toml and README.md describe crate metadata, dependencies, features.
• benches/ holds benchmark harnesses comparing Recloser vs. failsafe.
• src/ modules:
• lib.rs – public entrypoint re-exports types.
• recloser.rs – core Recloser struct and its state‐machine logic.
• ring_buffer.rs – lock-free ring buffer implementation for counting successes/failures.
• error.rs – error types (Error::Inner, Error::Rejected) and ErrorPredicate trait.
• async.rs – AsyncRecloser wrapper that adapts Recloser to Future-based calls.
README for additional insights
• Circuit-breaker has three states: Closed, Open, Half-Open.
• Configurable thresholds: error rate, buffer lengths, open timeout.
• API synopsis: call(...), call_with(predicate, ...), and async call(future).
• Performance focus: single vs. multi-thread benchmarks.
Essential detail reminders
• Three states and their transitions.
• How AsyncRecloser delegates to Recloser.
• Where ErrorPredicate intercepts and may filter out errors.