Skip to content

Instantly share code, notes, and snippets.

@bishtpawan
Created April 8, 2020 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bishtpawan/008649e5783a84a1f17a37301f764e6b to your computer and use it in GitHub Desktop.
Save bishtpawan/008649e5783a84a1f17a37301f764e6b to your computer and use it in GitHub Desktop.
This is the simple demonstration of async/await feature of Rust
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