// waiting for threads in rust // this example makes a single thread, and saves its "handle" // then waits for handle to end // so all thread actions are done use std::time::Duration; use std::thread; fn main() { // make a single thread let handle = thread::spawn(|| { for i in 1..10 { println!("hi number {} from the spawned thread!", i); thread::sleep(Duration::from_millis(1)); } }); for i in 1..5 { println!("hi number {} from the main thread!", i); thread::sleep(Duration::from_millis(1)); } // this will block until the thread completes handle.join().unwrap(); }