Skip to content

Instantly share code, notes, and snippets.

@mortymacs
Created May 28, 2022 17:12
Show Gist options
  • Save mortymacs/242d91aa546b5777203a4243669939b2 to your computer and use it in GitHub Desktop.
Save mortymacs/242d91aa546b5777203a4243669939b2 to your computer and use it in GitHub Desktop.
Sample Rust Tokio library for an infinit loop
use std::time::Duration;
async fn action() {
loop {
print!("Hello!");
tokio::time::sleep(Duration::from_millis(1)).await;
}
}
#[tokio::main]
async fn main() {
println!("Hello, world!");
let a = tokio::spawn(async{action().await;});
tokio::time::sleep(Duration::from_secs(1)).await;
a.abort();
print!("STOPED!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment