The circuit-breaker design pattern is based on the same concept as an electrical circuit. As you can see in the following diagram, when the circuit is open, the flow of electricity is impeded and cannot flow between the two points—the power source and light bulb in our example. When the circuit is closed, electricity is unimpeded and the light bulb can receive power:
Circuit breaker—light-switch example
The circuit-breaker design pattern is modeled after electrical circuits. This design pattern has three possible states:
- Open: If the state is open, then an error will be returned.
- Closed: This is the preferred state where functionality is permitted.
- Half-Open: This state is used after an open state error and a wait period. The function will allow one use as a test.
If the test is successful, the circuit will be closed...