File tree Expand file tree Collapse file tree 1 file changed +28
-6
lines changed Expand file tree Collapse file tree 1 file changed +28
-6
lines changed Original file line number Diff line number Diff line change 1
1
use core:: time:: Duration ;
2
2
3
+ /// Backoff is an [`Iterator`] that returns [`Duration`].
4
+ ///
5
+ /// - `Some(Duration)` indicates the caller should `sleep(Duration)` and retry the request.
6
+ /// - `None` indicates the limits have been reached, and the caller should return the current error instead.
7
+ pub trait Backoff : Iterator < Item = Duration > + Send + Sync + Unpin { }
8
+ impl < T > Backoff for T where T : Iterator < Item = Duration > + Send + Sync + Unpin { }
9
+
3
10
/// BackoffBuilder is utilized to construct a new backoff.
4
11
pub trait BackoffBuilder : Send + Sync + Unpin {
5
12
/// The associated backoff returned by this builder.
@@ -9,9 +16,24 @@ pub trait BackoffBuilder: Send + Sync + Unpin {
9
16
fn build ( self ) -> Self :: Backoff ;
10
17
}
11
18
12
- /// Backoff is an [`Iterator`] that returns [`Duration`].
13
- ///
14
- /// - `Some(Duration)` indicates the caller should `sleep(Duration)` and retry the request.
15
- /// - `None` indicates the limits have been reached, and the caller should return the current error instead.
16
- pub trait Backoff : Iterator < Item = Duration > + Send + Sync + Unpin { }
17
- impl < T > Backoff for T where T : Iterator < Item = Duration > + Send + Sync + Unpin { }
19
+ impl < B : Backoff > BackoffBuilder for B {
20
+ type Backoff = B ;
21
+
22
+ fn build ( self ) -> Self :: Backoff {
23
+ self
24
+ }
25
+ }
26
+
27
+ #[ cfg( test) ]
28
+ mod tests {
29
+ use super :: * ;
30
+
31
+ fn test_fn_builder ( b : impl BackoffBuilder ) {
32
+ let _ = b. build ( ) ;
33
+ }
34
+
35
+ #[ test]
36
+ fn test_backoff_builder ( ) {
37
+ test_fn_builder ( [ Duration :: from_secs ( 1 ) ] . into_iter ( ) )
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments