refactor(core): use idiomatic .min() in calculate_delay (#16314)
This commit is contained in:
@@ -27,10 +27,7 @@ impl BackoffCalculator {
|
|||||||
/// Calculate backoff delay for a given attempt index (0-based).
|
/// Calculate backoff delay for a given attempt index (0-based).
|
||||||
pub fn calculate_delay(config: &RetryConfig, attempt: u32) -> Duration {
|
pub fn calculate_delay(config: &RetryConfig, attempt: u32) -> Duration {
|
||||||
let pow = config.backoff_multiplier.powi(attempt as i32);
|
let pow = config.backoff_multiplier.powi(attempt as i32);
|
||||||
let mut delay_ms = (config.initial_backoff_ms as f32 * pow) as u64;
|
let delay_ms = ((config.initial_backoff_ms as f32 * pow) as u64).min(config.max_backoff_ms);
|
||||||
if delay_ms > config.max_backoff_ms {
|
|
||||||
delay_ms = config.max_backoff_ms;
|
|
||||||
}
|
|
||||||
|
|
||||||
let jitter = config.jitter_factor.clamp(0.0, 1.0);
|
let jitter = config.jitter_factor.clamp(0.0, 1.0);
|
||||||
if jitter > 0.0 {
|
if jitter > 0.0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user