rust 定时执行

tokio = { "version" = "1.10", features = ["full"] }
use tokio::time;

async fn print() {
    let mut interval = time::interval(time::Duration::from_secs(1));
    loop {
        interval.tick().await;
        println!("2333");
    }
}

#[tokio::main]
async fn main() {
    tokio::spawn(print());
    std::thread::sleep(std::time::Duration::from_secs(3));
}
2333
2333
2333
posted @ 2024-09-28 14:16  寻找繁星  阅读(8)  评论(0编辑  收藏  举报