async fn execute_with_retries<F, T, E, Fut>(f: F) -> Result<T, E>
where
    F: Fn() -> Fut,
    Fut: Future<Output = Result<T, E>>,
    E: std::fmt::Display,
{
    let mut backoff = get_backoff_policy();
    loop {
        match f().await {
            Ok(v) => return Ok(v),
            Err(e) => match backoff.next_backoff() {
                Some(interval) => {
                    eprintln!("Retrying due to: {}", &e);
                    std::thread::sleep(interval);
                }
                None => {
                    eprintln!("Failed due to: {}", &e);
                    return Err(e);
                }
            },
        }
    }
}
/// Tries calling function `f` a few times with exponential backoff until it
/// results an `Ok`. If after a while `f` has returned only `Err`s, gives up and
/// returns the last error.
Tries calling function `f` a few times with exponential backoff until it
results an `Ok`. If after a while `f` has returned only `Err`s, gives up and
returns the last error.
Tries calling function ` f ` a few times with exponential backoff until it results an ` Ok ` . If after a while ` f ` has returned only ` Err ` s gives up and returns the last error .
async fn execute_with_retries<F, T, E, Fut>(f: F) -> Result<T, E>
where
    F: Fn() -> Fut,
    Fut: Future<Output = Result<T, E>>,
    E: std::fmt::Display,
{
    let mut backoff = get_backoff_policy();
    loop {
        match f().await {
            Ok(v) => return Ok(v),
            Err(e) => match backoff.next_backoff() {
                Some(interval) => {
                    eprintln!("Retrying due to: {}", &e);
                    std::thread::sleep(interval);
                }
                None => {
                    eprintln!("Failed due to: {}", &e);
                    return Err(e);
                }
            },
        }
    }
}
async fn execute_with_retries < F , T , E , Fut > ( f : F ) -> Result < T , E > where F : Fn ( ) -> Fut , Fut : Future < Output = Result < T , E > > , E : std :: fmt :: Display , { let mut backoff = get_backoff_policy ( ) ; loop { match f ( ) . await { Ok ( v ) => return Ok ( v ) , Err ( e ) => match backoff . next_backoff ( ) { Some ( interval ) => { eprintln ! ( " " e ) ; std :: thread :: sleep ( interval ) ; } None => { eprintln ! ( " " e ) ; return Err ( e ) ; } } , } } }
Tries calling function `f` a few times with exponential backoff until it
results an `Ok`.
Tries calling function ` f ` a few times with exponential backoff until it results an ` Ok ` .
f
F
f
F