1use procspawn::{self, Pool};
2use std::thread;
3use std::time::Duration;
4
5fn main() {
6 procspawn::init();
7
8 let pool = Pool::new(4).unwrap();
9 let mut handles = vec![];
10
11 for counter in 0..8 {
12 handles.push(procspawn::spawn!(in pool, (counter) || {
13 thread::sleep(Duration::from_millis(500));
14 counter
15 }));
16 }
17
18 for handle in handles {
19 match handle.join() {
20 Ok(val) => println!("got result: {}", val),
21 Err(err) => {
22 let panic = err.panic_info().expect("got a non panic error");
23 println!("process panicked with {}", panic.message());
24 println!("{:#?}", panic);
25 }
26 }
27 }
28
29 pool.shutdown();
30}