pub repository
mirror.p-hatan.comretry
2.0.0Utility for wrapping an asynchronous function in automatic retry logic with exponential backoff, useful when making requests over network.
Readme
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.
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:
- 400 ms +/- 25%
- 800 ms +/- 25%
- 1600 ms +/- 25%
- 3200 ms +/- 25%
- 6400 ms +/- 25%
- 12800 ms +/- 25%
- 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.
final r = RetryOptions(attempts: 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
v2.0.0
- Expect complete API break.
- Initial release started from scratch, lifted from code in 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.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add retrypubspec.yaml
name: retry
version: 2.0.0
authors:
- Jonas Finnemann Jensen <jonasfj@google.com>
description: |
Utility for wrapping an asynchronous function in automatic retry logic with
exponential backoff, useful when making requests over network.
homepage: https://github.com/google/dart-neats/tree/master/retry
repository: https://github.com/google/dart-neats.git
issue_tracker: https://github.com/google/dart-neats/labels/pkg:retry
dev_dependencies:
test: ^1.5.1
pedantic: ^1.4.0
environment:
sdk: '>=2.0.0 <3.0.0'
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 1.0.0 | 2016-03-31T16:47:45.053Z | Download | 4d918240ea6fba89e4aaf814a7a6b40f9f72998ed04780db32d53a8f64989abc |
| 2.0.0 | 2019-03-22T14:21:00.391587Z | Download | 08c6fa9b59f216fb32259ffa7e4b0a5ed921777218760e4c3918e4d75a31341a |
| 3.0.0 | 2019-06-20T18:34:40.073842Z | Download | 7dec5e833bf587c0997c882b8ad46e5a0b69e68055817a738275691b556e25f7 |
| 3.0.0+1 | 2019-08-26T08:37:44.221096Z | Download | 0719943a7d596ee6ba9e53e5cff853ab276dd7125848f890e2853aebf8bfb1c9 |
| 3.0.1-null-safety.0 | 2020-11-02T13:46:25.148871Z | Download | dda0aaa6d66fdba3d27c3954a3326f4e4848f96eadf2ab81023324c178110023 |
| 3.0.1 | 2020-07-01T17:29:53.216548Z | Download | 6d0cc7caba6caa8a16bbb7b6d79a5328e708940541090bcbebe844d4e0811440 |
| 3.1.0-null-safety.0 | 2020-12-02T20:55:00.012653Z | Download | 64d274790adfd9e46b704459b91b2babde2ceeb3f7fa72327519998e3972da79 |
| 3.1.0 | 2021-03-01T18:27:00.565009Z | Download | 45dfeebaf095b606fdb9dbfb4c114cc204449bc274783b452658365e03afdbab |
| 3.1.1 | 2023-03-27T09:18:10.201498Z | Download | a8a1e475a100a0bdc73f529ca8ea1e9c9c76bec8ad86a1f47780139a34ce7aea |
| 3.1.2 | 2023-05-16T14:26:11.159498Z | Download | 822e118d5b3aafed083109c72d5f484c6dc66707885e07c0fbcb8b986bba7efc |
Dependencies
No direct dependencies declared.