CircuitBreaker class
Circuit breaker pattern to prevent cascading failures.
When a provider fails repeatedly, the circuit breaker opens and blocks further requests for a cooldown period. After the cooldown, it allows one test request (half-open) to check if the service recovered.
Constructors
- CircuitBreaker({required String name, int failureThreshold = 5, Duration resetTimeout = const Duration(seconds: 60)})
Properties
- failureThreshold → int
-
Number of failures before opening the circuit.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isAllowed → bool
-
Whether requests are currently allowed through.
no setter
- name → String
-
Name of this circuit (typically the provider name).
final
- resetTimeout → Duration
-
How long to keep the circuit open before testing again.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → CircuitState
-
Current state of the circuit.
no setter
Methods
-
execute<
T> (Future< T> action()) → Future<T> -
Executes
actionthrough the circuit breaker. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
recordFailure(
) → void - Records a failed request.
-
recordSuccess(
) → void - Records a successful request.
-
reset(
) → void - Resets the circuit breaker to closed state.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited