Created
April 8, 2020 05:52
-
-
Save bishtpawan/008649e5783a84a1f17a37301f764e6b to your computer and use it in GitHub Desktop.
This is the simple demonstration of async/await feature of Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use futures::executor::block_on; | |
use async_std::task; | |
use std::time::Duration; | |
async fn func_1() { | |
for i in 1..10 { | |
print!("f1 "); | |
if i == 5 { | |
task::sleep(Duration::from_secs(2)).await; | |
} | |
} | |
} | |
async fn func_2() { | |
for i in 1..10 { | |
print!("f2 "); | |
} | |
} | |
async fn compute() { | |
let first = func_1(); | |
let second = func_2(); | |
futures::join!(first, second); | |
} | |
fn main() { | |
block_on(compute()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment