It will be exactly 4. The operations do not start until you .await them. To run them concurrently, use tokio::spawn, tokio::join! or some other concurrency primitive.
that is because Future is lazy? It seems this is not a hard rule . How about by adding an attribute macro like this
fn load() {
let x = #[eager] tokio::fs::File::open("file1"); // work will start at this point
let y = #[eager] tokio::fs::File::open("file2"); // work will start at this point
x.get(); // pseudo code , will block until completed
y.get();
}
Yes it's because futures are lazy. And regarding your proposed macro, that's what tokio::spawn does.
#[tokio::main]
async fn load() {
let x = tokio::spawn(tokio::fs::File::open("file1"));
let y = tokio::spawn(tokio::fs::File::open("file2"));
x.await;
y.await;
}
You can't eliminate awaits and be sure that the async remains async. If your proposed get is blocking, then it will stop all tasks on the current thread, and we're back to the first step.