Function init

Source
pub fn init()
Expand description

Initializes procspawn.

This function must be called at the beginning of main. Whatever comes before it is also executed for all processes spawned through the spawn function.

For more complex initializations see ProcConfig.

Examples found in repository?
examples/kill.rs (line 5)
4fn main() {
5    procspawn::init();
6    let mut handle = spawn((), |()| loop {});
7    handle.kill().unwrap();
8}
More examples
Hide additional examples
examples/args.rs (line 4)
3fn main() {
4    procspawn::init();
5
6    let handle = spawn((), |()| std::env::args().collect::<Vec<_>>());
7
8    let args = handle.join().unwrap();
9
10    println!("args in subprocess: {:?}", args);
11}
examples/simple.rs (line 4)
3fn main() {
4    procspawn::init();
5
6    let handle = spawn((1, 2), |(a, b)| {
7        println!("in process: {:?} {:?}", a, b);
8        a + b
9    });
10
11    println!("result: {}", handle.join().unwrap());
12}
examples/timeout.rs (line 6)
5fn main() {
6    procspawn::init();
7
8    let mut handle = spawn((), |()| {
9        thread::sleep(Duration::from_secs(10));
10    });
11
12    println!("result: {:?}", handle.join_timeout(Duration::from_secs(1)));
13}
examples/macro.rs (line 4)
3fn main() {
4    procspawn::init();
5
6    let a = 42u32;
7    let b = 23u32;
8    let c = 1;
9    let handle = spawn!((a => new_name1, b, mut c) || -> Result<_, ()> {
10        c += 1;
11        Ok(new_name1 + b + c)
12    });
13    let value = handle.join().unwrap();
14
15    println!("{:?}", value);
16}
examples/custom-serialization.rs (line 72)
71fn main() {
72    procspawn::init();
73
74    let bytes = MyBytes::open("Cargo.toml").unwrap();
75
76    let bytes_two = procspawn::spawn!((bytes.clone() => bytes) || {
77        println!("length: {}", bytes.bytes.len());
78        bytes
79    })
80    .join()
81    .unwrap();
82
83    assert_eq!(bytes, bytes_two);
84}