mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-07-28 02:38:30 +00:00
move exponential backoff util to different submod
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
2259e2c82f
commit
7e4453620e
7 changed files with 39 additions and 33 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::{cmp, convert::TryFrom, time::Duration};
|
||||
use std::{cmp, convert::TryFrom};
|
||||
|
||||
pub use checked_ops::checked_ops;
|
||||
|
||||
|
@ -53,34 +53,6 @@ macro_rules! validated {
|
|||
($($input:tt)+) => { $crate::expected!($($input)+) }
|
||||
}
|
||||
|
||||
/// Returns false if the exponential backoff has expired based on the inputs
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn continue_exponential_backoff_secs(
|
||||
min: u64,
|
||||
max: u64,
|
||||
elapsed: Duration,
|
||||
tries: u32,
|
||||
) -> bool {
|
||||
let min = Duration::from_secs(min);
|
||||
let max = Duration::from_secs(max);
|
||||
continue_exponential_backoff(min, max, elapsed, tries)
|
||||
}
|
||||
|
||||
/// Returns false if the exponential backoff has expired based on the inputs
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn continue_exponential_backoff(
|
||||
min: Duration,
|
||||
max: Duration,
|
||||
elapsed: Duration,
|
||||
tries: u32,
|
||||
) -> bool {
|
||||
let min = min.saturating_mul(tries).saturating_mul(tries);
|
||||
let min = cmp::min(min, max);
|
||||
elapsed < min
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(clippy::as_conversions)]
|
||||
pub fn usize_from_f64(val: f64) -> Result<usize, Error> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue