Skip to content

Instantly share code, notes, and snippets.

@thorseraq
Created April 11, 2023 03:57
Show Gist options
  • Select an option

  • Save thorseraq/9f653282ca3e7b2c06efbdf971ecb054 to your computer and use it in GitHub Desktop.

Select an option

Save thorseraq/9f653282ca3e7b2c06efbdf971ecb054 to your computer and use it in GitHub Desktop.
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