-
-
Save snoyberg/f5fea804f2b6fb69ae6d1f75c8004fc5 to your computer and use it in GitHub Desktop.
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 async_std::task::{sleep, spawn}; | |
use std::time::Duration; | |
async fn sleepus() { | |
for i in 1..=10 { | |
println!("Sleepus {}", i); | |
sleep(Duration::from_millis(500)).await; | |
} | |
} | |
async fn interruptus() { | |
for i in 1..=5 { | |
println!("Interruptus {}", i); | |
sleep(Duration::from_millis(1000)).await; | |
} | |
} | |
fn main() { | |
async_std::task::block_on(async { | |
let sleepus = spawn(sleepus()); | |
interruptus().await; | |
sleepus.await; | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment