@@ -28,10 +28,9 @@ impl RetryStrategy {
28
28
let delays: Box < dyn Iterator < Item = Duration > + Send > = match delays {
29
29
RetryDelay :: Never => Box :: new ( std:: iter:: empty ( ) ) ,
30
30
RetryDelay :: Constant ( constant_delays) => Box :: new ( constant_delays. take ( max_retries) ) ,
31
- RetryDelay :: Exponential ( exponential_delays) => Box :: new (
32
- exponential_delays
33
- . take ( max_retries)
34
- ) ,
31
+ RetryDelay :: Exponential ( exponential_delays) => {
32
+ Box :: new ( exponential_delays. take ( max_retries) )
33
+ }
35
34
} ;
36
35
37
36
Jittered :: jitter ( delays)
@@ -45,6 +44,8 @@ pub enum RetryDelay {
45
44
Exponential ( ExponentialBackoff ) ,
46
45
}
47
46
47
+ /// Creates a retry strategy that never retries after failure.
48
+ /// The result needs to be consumed.
48
49
#[ no_mangle]
49
50
pub unsafe extern "C" fn mullvad_api_retry_strategy_never ( ) -> SwiftRetryStrategy {
50
51
let retry_strategy = RetryStrategy {
@@ -56,6 +57,8 @@ pub unsafe extern "C" fn mullvad_api_retry_strategy_never() -> SwiftRetryStrateg
56
57
return SwiftRetryStrategy ( ptr) ;
57
58
}
58
59
60
+ /// Creates a retry strategy that retries `max_retries` times with a constant delay of `delay_sec`.
61
+ /// The result needs to be consumed.
59
62
#[ no_mangle]
60
63
pub unsafe extern "C" fn mullvad_api_retry_strategy_constant (
61
64
max_retries : usize ,
@@ -71,17 +74,20 @@ pub unsafe extern "C" fn mullvad_api_retry_strategy_constant(
71
74
return SwiftRetryStrategy ( ptr) ;
72
75
}
73
76
77
+ /// Creates a retry strategy that retries `max_retries` times with a exponantially increating delay.
78
+ /// The delay will never exceed `max_delay_sec`
79
+ /// The result needs to be consumed.
74
80
#[ no_mangle]
75
81
pub unsafe extern "C" fn mullvad_api_retry_strategy_exponential (
76
82
max_retries : usize ,
77
- initial_seconds : u64 ,
83
+ initial_sec : u64 ,
78
84
factor : u32 ,
79
- max_delay : u64 ,
85
+ max_delay_sec : u64 ,
80
86
) -> SwiftRetryStrategy {
81
- let initial_delay = Duration :: from_secs ( initial_seconds ) ;
87
+ let initial_delay = Duration :: from_secs ( initial_sec ) ;
82
88
83
89
let backoff = ExponentialBackoff :: new ( initial_delay, factor)
84
- . max_delay ( Some ( Duration :: from_secs ( max_delay ) ) ) ;
90
+ . max_delay ( Some ( Duration :: from_secs ( max_delay_sec ) ) ) ;
85
91
86
92
let retry_strategy = RetryStrategy {
87
93
delays : RetryDelay :: Exponential ( backoff) ,
0 commit comments