Cannot seem to get the futures:join
macro to execute in parallel using tokio::main
.
Cargo.toml
[dependencies]
futures = "0.3"
tokio = { version = "1", features = ["full"] }
main.rs
use futures::join;
use std::time::{Duration, Instant};
use std::thread;
async fn do_io() { thread::sleep(Duration::from_millis(250)); }
async fn fetch() -> ((), ()) {
join!(do_io(), do_io())
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let s = Instant::now();
fetch().await;
let d = s.elapsed();
println!("{:?}", d);
Ok(())
}
Expected Output
~250ms
Actual Output
~500ms