procspawn

Crates.ioprocspawn
lib.rsprocspawn
version1.0.1
sourcesrc
created_at2020-02-08 14:11:47.697294
updated_at2024-08-06 21:24:32.273234
descriptionthread::spawn just with processes
homepagehttps://github.com/mitsuhiko/procspawn
repositoryhttps://github.com/mitsuhiko/procspawn
max_upload_size
id206359
size129,126
Armin Ronacher (mitsuhiko)

documentation

README

procspawn

Build Status Crates.io Documentation rustc 1.65.0

This crate provides the ability to spawn processes with a function similar to thread::spawn. Instead of closures it passes serde serializable objects. The return value from the spawned closure also must be serializable and can then be retrieved from the returned join handle.

If the spawned functiom causes a panic it will also be serialized across the process boundaries.

Example

Step 1: invoke procspawn::init at a point early in your program (somewhere at the beginning of the main function). Whatever happens before that point also happens in your spawned functions.

procspawn::init();

Step 2: now you can start spawning functions:

let data = vec![1, 2, 3, 4];
let handle = procspawn::spawn(data, |data| {
    println!("Received data {:?}", &data);
    data.into_iter().sum::<i64>()
});
let result = handle.join().unwrap();

License and Links

Commit count: 156

cargo fmt