union_spawn

Macro union_spawn 

Source
macro_rules! union_spawn {
    ($($proc_macro:tt)*) => { ... };
}
Expand description

Use to spawn ::std::thread per each step of each branch.

extern crate union;

use union::union_spawn;

fn main() {
    let product = union_spawn! {
        Ok::<_,u8>(2) |> |v| v + 2 ?> |_| {
            println!("Hello from parallel world!");
            ::std::thread::sleep(::std::time::Duration::from_secs(1));
            println!("I'm done.");
        },
        Ok::<_,u8>(3) ?> |_| {
            println!("Hello from parallel world again!");
            ::std::thread::sleep(::std::time::Duration::from_secs(2));
            println!("Me too.");
        },
        Ok::<_,u8>(4),
        map => |a, b, c| a * b * c
    }.unwrap();

    assert_eq!(product, 48);
}