pub async fn wait_random<T: SampleRange<u64>>(range: T)
Expand description

Util to asynchronously wait for some random number milliseconds.

Examples

use cs_utils::asyn::wait_random;
use tokio::time::{Instant, Duration};
 
#[tokio::main]
async fn main() {
    let start_time = Instant::now();
    println!("start");
    wait_random(500..1000).await;
    println!("end");
     
    assert!(
        (Instant::now() - start_time) >= Duration::from_millis(500),
    );
 
    assert!(
        (Instant::now() - start_time) <= Duration::from_millis(1000 + 100),
    );
}