# retry 3.1.0

Utility for wrapping an asynchronous function in automatic retry logic with
exponential back-off, useful when making requests over network.





## Installing
```
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'retry:3.1.0'
```
Published: 2021-03-01T18:27:00.565009Z
Expected archive SHA-256: 45dfeebaf095b606fdb9dbfb4c114cc204449bc274783b452658365e03afdbab

Available in cache; verification: upstream_checksum
## Direct dependencies

## Package README (untrusted upstream documentation)
Retry for dart
==============

This package provides an easy way to retry asynchronous functions. This is
often useful to avoid crashing on intermittent errors such as broken
connections or temporarily overloaded servers.

**Disclaimer:** This is not an officially supported Google product.

## Using `retry`
For simple retry logic with exponential back-off use the `retry` function
provided by this package.

```dart
import 'package:retry/retry.dart';

final response = await retry(
  // Make a GET request
  () => http.get('https://google.com').timeout(Duration(seconds: 5)),
  // Retry on SocketException or TimeoutException
  retryIf: (e) => e is SocketException || e is TimeoutException,
);
print(response.body);
```

Defaults to 8 attempts, sleeping as following after 1st, 2nd, 3rd, ...,
7th attempt:
 1. 400 ms +/- 25%
 2. 800 ms +/- 25%
 3. 1600 ms +/- 25%
 4. 3200 ms +/- 25%
 5. 6400 ms +/- 25%
 6. 12800 ms +/- 25%
 7. 25600 ms +/- 25%

## Using `RetryOptions`
This package provides `RetryOptions` which defined how many times to retry
an function and how long to sleep between retries.

```dart
final r = RetryOptions(maxAttempts: 8);
final response = await r.retry(
  // Make a GET request
  () => http.get('https://google.com').timeout(Duration(seconds: 5)),
  // Retry on SocketException or TimeoutException
  retryIf: (e) => e is SocketException || e is TimeoutException,
);
print(response.body);
```

## Changelog
## v3.1.0
 * Stable null-safety release.

## v3.1.0-null-safety.0
 * Migrate to null-safety.

## v3.0.1
 * Fix retry overflow

## v3.0.0+1
 * Update the example in `README.md`.

## v3.0.0
 * When `retryIf` is not given, we default to retry any `Exception` thrown.
   This is breaking, but provides a more useful default behavior.

## v2.0.0
 * Expect complete API break.
 * Initial release started from scratch, lifted from code in
   [github.com/dart-lang/pub-dartlang-dart](https://github.com/dart-lang/pub-dartlang-dart).
 * Credits to Tim Kluge for transferring ownership.
 * Dart 2.0 support.

## v1.0.0
 * Initial release by Tim Kluge from 
   [github.com/gwTumm/dart-retry](https://github.com/gwTumm/dart-retry).







 
