philiprehberger_retry 0.1.0 copy "philiprehberger_retry: ^0.1.0" to clipboard
philiprehberger_retry: ^0.1.0 copied to clipboard

Configurable retry with exponential backoff, jitter, and circuit breaker

philiprehberger_retry #

Tests pub package Last updated

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:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License #

MIT

1
likes
160
points
--
downloads

Documentation

API reference

Publisher

verified publisherphiliprehberger.com

Weekly Downloads

Configurable retry with exponential backoff, jitter, and circuit breaker

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on philiprehberger_retry