Configurable retry with exponential backoff, jitter, and circuit breaker
dart pub add philiprehberger_retryConfigurable retry with exponential backoff, jitter, and circuit breaker
Add to your pubspec.yaml:
dependencies:
philiprehberger_retry: ^0.1.0
Then run:
dart pub get
import 'package:philiprehberger_retry/philiprehberger_retry.dart';
final result = await retry(() => fetchData());
final result = await retry(
() => fetchData(),
maxAttempts: 5,
delay: Duration(milliseconds: 500),
backoffMultiplier: 1.5,
jitter: true,
timeout: Duration(seconds: 10),
);
final result = await retry(
() => fetchData(),
retryIf: (e) => e is SocketException,
);
final breaker = CircuitBreaker(
failureThreshold: 3,
resetTimeout: Duration(seconds: 30),
);
try {
final result = await breaker.execute(() => fetchData());
} on CircuitBreakerOpenException {
print('Circuit is open, skipping call');
}
| Symbol | Description |
|---|---|
retry() | Retry an async operation with configurable backoff |
CircuitBreaker | Prevents repeated calls to a failing service |
CircuitBreaker.execute() | Execute a function through the circuit breaker |
CircuitBreaker.state | Current circuit state (closed, open, halfOpen) |
CircuitBreaker.reset() | Reset the circuit breaker to closed state |
CircuitState | Enum: closed, open, halfOpen |
CircuitBreakerOpenException | Thrown when executing through an open circuit |
dart pub get
dart analyze --fatal-infos
dart test
If you find this project useful: