xref: /DragonOS/user/apps/test_tokio/src/main.rs (revision fae6e9ade46a52976ad5d099643d51cc20876448)

say_world()1*4afc5b7bSlinfeng async fn say_world() {
2*4afc5b7bSlinfeng     println!("world");
3*4afc5b7bSlinfeng }
4*4afc5b7bSlinfeng 
5*4afc5b7bSlinfeng #[tokio::main(flavor = "current_thread")]
main()6*4afc5b7bSlinfeng async fn main() {
7*4afc5b7bSlinfeng     // Calling `say_world()` does not execute the body of `say_world()`.
8*4afc5b7bSlinfeng     let op = say_world();
9*4afc5b7bSlinfeng 
10*4afc5b7bSlinfeng     // This println! comes first
11*4afc5b7bSlinfeng     println!("hello");
12*4afc5b7bSlinfeng 
13*4afc5b7bSlinfeng     // Calling `.await` on `op` starts executing `say_world`.
14*4afc5b7bSlinfeng     op.await;
15*4afc5b7bSlinfeng }
16