File tree 4 files changed +34
-4
lines changed
4 files changed +34
-4
lines changed Original file line number Diff line number Diff line change
1
+ ## v3.0.0
2
+ * When ` retryIf ` is not given, we default to retry any ` Exception ` thrown.
3
+ This is breaking, but provides a more useful default behavior.
4
+
1
5
## v2.0.0
2
6
* Expect complete API break.
3
7
* Initial release started from scratch, lifted from code in
Original file line number Diff line number Diff line change @@ -113,6 +113,10 @@ class RetryOptions {
113
113
///
114
114
/// At every retry the [onRetry] function will be called (if given). The
115
115
/// function [fn] will be invoked at-most [this.attempts] times.
116
+ ///
117
+ /// If no [retryIf] function is given this will retry any for any [Exception]
118
+ /// thrown. To retry on an [Error] , the error must be caught and _rethrown_
119
+ /// as an [Exception] .
116
120
Future <T > retry <T >(
117
121
FutureOr <T > Function () fn, {
118
122
FutureOr <bool > Function (Exception ) retryIf,
@@ -125,7 +129,8 @@ class RetryOptions {
125
129
try {
126
130
return await fn ();
127
131
} on Exception catch (e) {
128
- if (attempt >= maxAttempts || retryIf == null || ! (await retryIf (e))) {
132
+ if (attempt >= maxAttempts ||
133
+ (retryIf != null && ! (await retryIf (e)))) {
129
134
rethrow ;
130
135
}
131
136
if (onRetry != null ) {
@@ -161,6 +166,10 @@ class RetryOptions {
161
166
/// );
162
167
/// print(response.body);
163
168
/// ```
169
+ ///
170
+ /// If no [retryIf] function is given this will retry any for any [Exception]
171
+ /// thrown. To retry on an [Error] , the error must be caught and _rethrown_
172
+ /// as an [Exception] .
164
173
Future <T > retry <T >(
165
174
FutureOr <T > Function () fn, {
166
175
Duration delayFactor = const Duration (milliseconds: 200 ),
Original file line number Diff line number Diff line change 1
1
name : retry
2
- version : 2 .0.0
2
+ version : 3 .0.0
3
3
authors :
4
4
-
Jonas Finnemann Jensen <[email protected] >
5
5
description : |
6
6
Utility for wrapping an asynchronous function in automatic retry logic with
7
- exponential backoff , useful when making requests over network.
7
+ exponential back-off , useful when making requests over network.
8
8
homepage : https://github.com/google/dart-neats/tree/master/retry
9
9
repository : https://github.com/google/dart-neats.git
10
10
issue_tracker : https://github.com/google/dart-neats/labels/pkg:retry
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ void main() {
57
57
final f = r.retry (() {
58
58
count++ ;
59
59
throw Exception ('Retry will fail' );
60
- });
60
+ }, retryIf : (e) => false );
61
61
await expectLater (f, throwsA (isException));
62
62
expect (count, equals (1 ));
63
63
});
@@ -93,6 +93,23 @@ void main() {
93
93
expect (count, equals (2 ));
94
94
});
95
95
96
+ test ('retry (no retryIf)' , () async {
97
+ int count = 0 ;
98
+ final r = RetryOptions (
99
+ maxAttempts: 5 ,
100
+ maxDelay: Duration (),
101
+ );
102
+ final f = r.retry (() {
103
+ count++ ;
104
+ if (count == 1 ) {
105
+ throw FormatException ('Retry will be okay' );
106
+ }
107
+ return true ;
108
+ });
109
+ await expectLater (f, completion (isTrue));
110
+ expect (count, equals (2 ));
111
+ });
112
+
96
113
test ('retry (unhandled on 2nd try)' , () async {
97
114
int count = 0 ;
98
115
final r = RetryOptions (
You can’t perform that action at this time.
0 commit comments