
#[cfg(feature = "use_async")]
pub async fn retry_async<F: FnMut() -> T, T: std::future::Future<Output = Result<R, E>>, R, E>(mut f: F, count: u64, _millis: u64) -> Result<R, E> {
    for i in 0..=count {
        let mut r = f().await;

        if let Err(_e) = &r {
            debug!("retry_async[{}]", i);
        }

        if r.is_ok() || i >= count {
            return r;
        }

        tokio::time::sleep(std::time::Duration::from_millis(_millis)).await;
    }
    unreachable!("loop u64: 0..=0")
}

#[cfg(feature = "tokio")]
pub fn call_async_by_tokio<F: std::future::Future>(fut: F) -> F::Output {
    tokio::task::block_in_place(|| tokio::runtime::Handle::current().block_on(fut))
}

pub fn retry<F: FnMut() -> Result<R, E>, R, E>(mut f: F, count: u64, _millis: u64) -> Result<R, E>{
    for i in 0..=count {
        let r = f();

        if let Err(_e) = &r {
            debug!("retry[{}]", i);
        }

        if r.is_ok() || i >= count {
            return r;
        }

        std::thread::sleep(std::time::Duration::from_millis(_millis));
    }
    unreachable!("loop: 0..=0")
}
