p-hatan/ mirror

pub repository

mirror.p-hatan.com

retry

2.0.0

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

Download archive

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:

  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.

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

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add retry
pubspec.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

VersionPublishedArchiveSHA-256
1.0.02016-03-31T16:47:45.053ZDownload4d918240ea6fba89e4aaf814a7a6b40f9f72998ed04780db32d53a8f64989abc
2.0.02019-03-22T14:21:00.391587ZDownload08c6fa9b59f216fb32259ffa7e4b0a5ed921777218760e4c3918e4d75a31341a
3.0.02019-06-20T18:34:40.073842ZDownload7dec5e833bf587c0997c882b8ad46e5a0b69e68055817a738275691b556e25f7
3.0.0+12019-08-26T08:37:44.221096ZDownload0719943a7d596ee6ba9e53e5cff853ab276dd7125848f890e2853aebf8bfb1c9
3.0.1-null-safety.02020-11-02T13:46:25.148871ZDownloaddda0aaa6d66fdba3d27c3954a3326f4e4848f96eadf2ab81023324c178110023
3.0.12020-07-01T17:29:53.216548ZDownload6d0cc7caba6caa8a16bbb7b6d79a5328e708940541090bcbebe844d4e0811440
3.1.0-null-safety.02020-12-02T20:55:00.012653ZDownload64d274790adfd9e46b704459b91b2babde2ceeb3f7fa72327519998e3972da79
3.1.02021-03-01T18:27:00.565009ZDownload45dfeebaf095b606fdb9dbfb4c114cc204449bc274783b452658365e03afdbab
3.1.12023-03-27T09:18:10.201498ZDownloada8a1e475a100a0bdc73f529ca8ea1e9c9c76bec8ad86a1f47780139a34ce7aea
3.1.22023-05-16T14:26:11.159498ZDownload822e118d5b3aafed083109c72d5f484c6dc66707885e07c0fbcb8b986bba7efc

Dependencies

No direct dependencies declared.