Three states, and the transitions between them are the whole mechanism.
Closed — calls pass through. A run of failures reaching the threshold trips it. Open — no call is made at all. The caller fails immediately with the breaker's own error, in microseconds instead of a 30-second connect timeout. Half-open — reached after a cooldown. Exactly one probe is allowed through. Success closes the breaker and clears the failure run; failure re-opens it and restarts the cooldown.
The exercise prints the whole walk: trip at t=5, probes at t=9, 13 and 17, close at 17. Note what the breaker buys while the dependency is still down — 9 of 22 ticks short-circuited, which is 9 threads or connection slots never blocked on a doomed call.
That is the real point. A breaker protects the caller from resource exhaustion at least as much as it protects the callee.
