@@ -45,53 +45,53 @@ impl RetryBackoffBuilder {
4545 RetryBackoff {
4646 min_base_delay : self . min_base_delay ,
4747 max_base_delay : self . max_base_delay ,
48- max_attempts : self . max_retries ,
49- cur_attempt : 0 ,
48+ max_retries : self . max_retries ,
49+ cur_retry : 0 ,
5050 }
5151 }
5252}
5353
5454pub struct RetryBackoff {
5555 min_base_delay : Duration ,
5656 max_base_delay : Duration ,
57- max_attempts : u32 ,
58- cur_attempt : u32 ,
57+ max_retries : u32 ,
58+ cur_retry : u32 ,
5959}
6060
6161impl RetryBackoff {
6262 pub fn remaining ( & self ) -> u32 {
63- self . max_attempts . saturating_sub ( self . cur_attempt )
63+ self . max_retries . saturating_sub ( self . cur_retry )
6464 }
6565
6666 pub fn is_exhausted ( & self ) -> bool {
67- self . cur_attempt >= self . max_attempts
67+ self . cur_retry >= self . max_retries
6868 }
6969
7070 pub fn reset ( & mut self ) {
71- self . cur_attempt = 0 ;
71+ self . cur_retry = 0 ;
7272 }
7373
74- pub fn attempts_used ( & self ) -> u32 {
75- self . cur_attempt
74+ pub fn used ( & self ) -> u32 {
75+ self . cur_retry
7676 }
7777}
7878
7979impl Iterator for RetryBackoff {
8080 type Item = Duration ;
8181
8282 fn next ( & mut self ) -> Option < Self :: Item > {
83- if self . cur_attempt == self . max_attempts {
83+ if self . cur_retry == self . max_retries {
8484 return None ;
8585 }
8686 let base_delay = ( self
8787 . min_base_delay
88- . saturating_mul ( 2u32 . saturating_pow ( self . cur_attempt ) ) )
88+ . saturating_mul ( 2u32 . saturating_pow ( self . cur_retry ) ) )
8989 . min ( self . max_base_delay ) ;
9090 let jitter =
9191 Duration :: try_from_secs_f64 ( base_delay. as_secs_f64 ( ) * rng ( ) . random_range ( 0.0 ..=1.0 ) )
9292 . unwrap_or ( Duration :: MAX ) ;
9393 let delay = base_delay + jitter;
94- self . cur_attempt += 1 ;
94+ self . cur_retry += 1 ;
9595 Some ( delay)
9696 }
9797}
@@ -131,31 +131,31 @@ mod tests {
131131 fn backoff_with_reset ( ) {
132132 let mut backoff = RetryBackoffBuilder :: default ( ) . with_max_retries ( 3 ) . build ( ) ;
133133
134- assert_eq ! ( backoff. attempts_used ( ) , 0 ) ;
134+ assert_eq ! ( backoff. used ( ) , 0 ) ;
135135 assert_eq ! ( backoff. remaining( ) , 3 ) ;
136136 assert ! ( !backoff. is_exhausted( ) ) ;
137137
138138 assert ! ( backoff. next( ) . is_some( ) ) ;
139- assert_eq ! ( backoff. attempts_used ( ) , 1 ) ;
139+ assert_eq ! ( backoff. used ( ) , 1 ) ;
140140 assert_eq ! ( backoff. remaining( ) , 2 ) ;
141141 assert ! ( !backoff. is_exhausted( ) ) ;
142142
143143 backoff. reset ( ) ;
144144
145- assert_eq ! ( backoff. attempts_used ( ) , 0 ) ;
145+ assert_eq ! ( backoff. used ( ) , 0 ) ;
146146 assert_eq ! ( backoff. remaining( ) , 3 ) ;
147147 assert ! ( !backoff. is_exhausted( ) ) ;
148148
149149 assert ! ( backoff. next( ) . is_some( ) ) ;
150- assert_eq ! ( backoff. attempts_used ( ) , 1 ) ;
150+ assert_eq ! ( backoff. used ( ) , 1 ) ;
151151 assert_eq ! ( backoff. remaining( ) , 2 ) ;
152152
153153 assert ! ( backoff. next( ) . is_some( ) ) ;
154- assert_eq ! ( backoff. attempts_used ( ) , 2 ) ;
154+ assert_eq ! ( backoff. used ( ) , 2 ) ;
155155 assert_eq ! ( backoff. remaining( ) , 1 ) ;
156156
157157 assert ! ( backoff. next( ) . is_some( ) ) ;
158- assert_eq ! ( backoff. attempts_used ( ) , 3 ) ;
158+ assert_eq ! ( backoff. used ( ) , 3 ) ;
159159 assert_eq ! ( backoff. remaining( ) , 0 ) ;
160160 assert ! ( backoff. is_exhausted( ) ) ;
161161
0 commit comments