Created
April 11, 2023 03:57
-
-
Save thorseraq/9f653282ca3e7b2c06efbdf971ecb054 to your computer and use it in GitHub Desktop.
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::sync::Arc; | |
| use std::thread::sleep; | |
| use tokio::runtime::Runtime; | |
| fn main() { | |
| let rt = Arc::new(Runtime::new().unwrap()); | |
| rt.spawn(async { | |
| tokio::time::sleep(std::time::Duration::from_secs(1)).await; | |
| println!("finished"); | |
| }); | |
| { | |
| for i in 0..10 { | |
| let rt = rt.clone(); | |
| std::thread::spawn(move || { | |
| rt.spawn(async { | |
| tokio::time::sleep(std::time::Duration::from_secs(1)).await; | |
| println!("finished"); | |
| }); | |
| }); | |
| } | |
| } | |
| sleep(std::time::Duration::from_secs(10)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment