In Rust, Future is known to be lazy. Is it specific to tokio runtime?
In Rust, calling an async function without await does NOT actually evaluate the function as Future is lazy.
For example, the code below does NOT print hello although the equivalent code in other languages (e.g. Dart) prints hello.
async fn g() {
println!("hello");
}
async fn f() {
g();
}
#[tokio::main]
async fn main() {
f().await;
std::thread::sleep(std::time::Duration::from_millis(1000));
}
Is this behavior guaranteed by the language level? Or, is it specific to tokio runtime?
For those who are interested: the equivalent code in Dart
import 'dart:io';
Future<void> g() async {
print("hello");
}
Future<void> f() async {
g();
}
void main() async {
await f();
sleep(Duration(seconds: 1));
}