Skip to content

Instantly share code, notes, and snippets.

@snoyberg

snoyberg/main.rs Secret

Created November 29, 2019 10:22
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 snoyberg/f5fea804f2b6fb69ae6d1f75c8004fc5 to your computer and use it in GitHub Desktop.
Save snoyberg/f5fea804f2b6fb69ae6d1f75c8004fc5 to your computer and use it in GitHub Desktop.
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