Practice · 1 of 2
Circuit breaker state machine
CHALLENGE
Difficulty: advanced+25 XP
Implement class CircuitBreaker(int failureThreshold, TimeSpan openDuration) with method bool TryExecute(Action action): CLOSED executes and counts consecutive failures (resetting on success); at threshold it opens for openDuration (TryExecute returns false immediately while open); after the duration it becomes HALF-OPEN, letting one attempt through — success closes, failure re-opens. Implement string State returning "closed", "open", or "half-open".
Press Submit to check your solution.
Back to lesson: Practice: Diagnostics drills