Created
May 28, 2022 17:12
-
-
Save mortymacs/242d91aa546b5777203a4243669939b2 to your computer and use it in GitHub Desktop.
Sample Rust Tokio library for an infinit loop
This file contains hidden or 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 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