philiprehberger_retry
Configurable retry with exponential backoff, jitter, and circuit breaker
Requirements
- Dart >= 3.6
Installation
Add to your pubspec.yaml:
dependencies:
philiprehberger_retry: ^0.1.0
Then run:
dart pub get
Usage
import 'package:philiprehberger_retry/philiprehberger_retry.dart';
final result = await retry(() => fetchData());
Retry with Custom Options
final result = await retry(
() => fetchData(),
maxAttempts: 5,
delay: Duration(milliseconds: 500),
backoffMultiplier: 1.5,
jitter: true,
timeout: Duration(seconds: 10),
);
Retry Only Specific Exceptions
final result = await retry(
() => fetchData(),
retryIf: (e) => e is SocketException,
);
Circuit Breaker
final breaker = CircuitBreaker(
failureThreshold: 3,
resetTimeout: Duration(seconds: 30),
);
try {
final result = await breaker.execute(() => fetchData());
} on CircuitBreakerOpenException {
print('Circuit is open, skipping call');
}
API
| 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 |
Development
dart pub get
dart analyze --fatal-infos
dart test
Support
If you find this project useful:
License
Libraries
- philiprehberger_retry
- Configurable retry with exponential backoff, jitter, and circuit breaker.
- retry