@@ -18,16 +18,16 @@ class RetryClient extends BaseClient {
18
18
final int _retries;
19
19
20
20
/// The callback that determines whether a request should be retried.
21
- final bool Function (BaseResponse ) _when;
21
+ final FutureOr < bool > Function (BaseResponse ) _when;
22
22
23
23
/// The callback that determines whether a request when an error is thrown.
24
- final bool Function (Object , StackTrace ) _whenError;
24
+ final FutureOr < bool > Function (Object , StackTrace ) _whenError;
25
25
26
26
/// The callback that determines how long to wait before retrying a request.
27
27
final Duration Function (int ) _delay;
28
28
29
29
/// The callback to call to indicate that a request is being retried.
30
- final void Function (BaseRequest , BaseResponse ? , int )? _onRetry;
30
+ final FutureOr < void > Function (BaseRequest , BaseResponse ? , int )? _onRetry;
31
31
32
32
/// Creates a client wrapping [_inner] that retries HTTP requests.
33
33
///
@@ -51,10 +51,11 @@ class RetryClient extends BaseClient {
51
51
RetryClient (
52
52
this ._inner, {
53
53
int retries = 3 ,
54
- bool Function (BaseResponse ) when = _defaultWhen,
55
- bool Function (Object , StackTrace ) whenError = _defaultWhenError,
54
+ FutureOr < bool > Function (BaseResponse ) when = _defaultWhen,
55
+ FutureOr < bool > Function (Object , StackTrace ) whenError = _defaultWhenError,
56
56
Duration Function (int retryCount) delay = _defaultDelay,
57
- void Function (BaseRequest , BaseResponse ? , int retryCount)? onRetry,
57
+ FutureOr <void > Function (BaseRequest , BaseResponse ? , int retryCount)?
58
+ onRetry,
58
59
}) : _retries = retries,
59
60
_when = when ,
60
61
_whenError = whenError,
@@ -72,9 +73,10 @@ class RetryClient extends BaseClient {
72
73
RetryClient .withDelays (
73
74
Client inner,
74
75
Iterable <Duration > delays, {
75
- bool Function (BaseResponse ) when = _defaultWhen,
76
- bool Function (Object , StackTrace ) whenError = _defaultWhenError,
77
- void Function (BaseRequest , BaseResponse ? , int retryCount)? onRetry,
76
+ FutureOr <bool > Function (BaseResponse ) when = _defaultWhen,
77
+ FutureOr <bool > Function (Object , StackTrace ) whenError = _defaultWhenError,
78
+ FutureOr <void > Function (BaseRequest , BaseResponse ? , int retryCount)?
79
+ onRetry,
78
80
}) : this ._withDelays (
79
81
inner,
80
82
delays.toList (),
@@ -86,9 +88,9 @@ class RetryClient extends BaseClient {
86
88
RetryClient ._withDelays (
87
89
Client inner,
88
90
List <Duration > delays, {
89
- required bool Function (BaseResponse ) when ,
90
- required bool Function (Object , StackTrace ) whenError,
91
- required void Function (BaseRequest , BaseResponse ? , int )? onRetry,
91
+ required FutureOr < bool > Function (BaseResponse ) when ,
92
+ required FutureOr < bool > Function (Object , StackTrace ) whenError,
93
+ required FutureOr < void > Function (BaseRequest , BaseResponse ? , int )? onRetry,
92
94
}) : this (
93
95
inner,
94
96
retries: delays.length,
@@ -108,19 +110,19 @@ class RetryClient extends BaseClient {
108
110
try {
109
111
response = await _inner.send (_copyRequest (request, splitter.split ()));
110
112
} catch (error, stackTrace) {
111
- if (i == _retries || ! _whenError (error, stackTrace)) rethrow ;
113
+ if (i == _retries || ! await _whenError (error, stackTrace)) rethrow ;
112
114
}
113
115
114
116
if (response != null ) {
115
- if (i == _retries || ! _when (response)) return response;
117
+ if (i == _retries || ! await _when (response)) return response;
116
118
117
119
// Make sure the response stream is listened to so that we don't leave
118
120
// dangling connections.
119
121
_unawaited (response.stream.listen ((_) {}).cancel ().catchError ((_) {}));
120
122
}
121
123
122
124
await Future <void >.delayed (_delay (i));
123
- _onRetry? .call (request, response, i);
125
+ await _onRetry? .call (request, response, i);
124
126
i++ ;
125
127
}
126
128
}
0 commit comments