use tokio::{time};
async fn hh1(){
for _ in 0..10{
time::sleep(std::time::Duration::from_secs(3)).await;
println!("11");
}
}
async fn hh2(){
for _ in 0..20{
time::sleep(std::time::Duration::from_secs(2)).await;
println!("22");
}
}
async fn hh3(){
let d1 = hh1();
let d2 = hh2();
tokio::join!(d1,d2);
}
#[tokio::main]
async fn main() {
// Open a connection to the mini-redis address.
hh3().await;
}
标签:await,tokio,sleep,延时,time,async,多任务,fn
From: https://www.cnblogs.com/hardfood/p/17714499.html