❮ tokio
❯
Simple async example with Tokio
examples/tokio/simple/Cargo.toml
[package] name = "simple" version = "0.1.0" edition = "2021" [dependencies] tokio = { version = "1.39.2", features = ["full"] }
examples/tokio/simple/src/main.rs
async fn do_something() { println!("Start to do something"); tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; println!("End to do something"); } fn main() { println!("Start"); let rt = tokio::runtime::Runtime::new().unwrap(); let future = do_something(); println!("Before block"); rt.block_on(future); println!("End"); }
Start Before block Start to do something End to do something End