Hard Resilience Patterns
Circuit Breaker Simulation
Simulate a circuit breaker. Create a call counter and a function callService() that:
- Calls 1-3: return error "Service down"
- Calls 4+: return "Service recovered"
Use retry(3) and doOnError to log each failure. Print the final result.
Expected
Failed: Service down (call 1) Failed: Service down (call 2) Failed: Service down (call 3) Service recovered
Main.kt