Problem, as an interviewer would state it: "Implement a circuit breaker wrapping a flaky async function — after enough real failures, STOP calling the real function entirely for a cooldown period, then cautiously try again."
Examples:
const breaker = createCircuitBreaker(flakyApi, { failureThreshold: 3 });
// after 3 real failures, breaker.call() rejects IMMEDIATELY, without even invoking flakyApi
Clarifying questions expected:
- What are the real, standard circuit-breaker states, and what triggers each transition between them?
- After the cooldown period, does the breaker immediately go back to normal, or cautiously test ONE real call first?
- Should a successful call during the cautious "testing" phase fully reset the breaker back to normal?
Code / implementation expected: Yes — real, direct proof of a FULL real state cycle: real failures tripping it open, an immediately-rejected call while open (with a real call counter confirming the function was genuinely never invoked), and real recovery after the cooldown.