1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use procspawn::{self, Pool};
use std::thread;
use std::time::Duration;

fn main() {
    procspawn::init();

    let pool = Pool::new(4).unwrap();
    let mut handles = vec![];

    for counter in 0..8 {
        handles.push(procspawn::spawn!(in pool, (counter) || {
            thread::sleep(Duration::from_millis(500));
            counter
        }));
    }

    for handle in handles {
        match handle.join() {
            Ok(val) => println!("got result: {}", val),
            Err(err) => {
                let panic = err.panic_info().expect("got a non panic error");
                println!("process panicked with {}", panic.message());
                println!("{:#?}", panic);
            }
        }
    }

    pool.shutdown();
}