Je suis en train de lancer deux fonctions en parallèle avec join
.
Mon code est simple:
tokio = { version = "1.14.0", features = ["full"] }
use tokio::join;
use std::thread::sleep;
use std::time::{Duration, Instant};
async fn fn_1() -> i8 {
sleep(Duration::from_secs(2));
2
}
async fn fn_2() -> i8 {
sleep(Duration::from_secs(2));
1
}
#[tokio::main]
async fn main() -> () {
let now = Instant::now();
println!("start: {:#?}", now.elapsed());
let a = fn_1();
let b = fn_2();
join!(a, b);
println!("end: {:#?}", now.elapsed());
}
Mais peu importe ce que je fais, cela prend 4s —2s + 2s
—, alors qu'il devrait prendre 2s si je ne me trompe pas:
start: 37ns
end: 4.01036111s
Est-il quelque chose que je suis absent?