macro_rules! union_async_spawn {
($($proc_macro:tt)*) => { ... };
}Expand description
Use to spawn ::tokio::spawn per each step of each branch.
#![recursion_limit="512"]
extern crate union;
extern crate futures;
extern crate tokio;
use union::union_async_spawn;
use futures::future::ok;
#[tokio::main]
async fn main() {
let product = union_async_spawn! {
ok::<_,u8>(2u16) |> |v| Ok::<_,u8>(v.unwrap() + 2u16) ?> |_| {
println!("Hello from parallel world!");
// !!! Don't use std::thread::sleep to wait inside future because it will block executor thread !!!
// It's used here only to show that futures are executed on multi thread executor.
::std::thread::sleep(::std::time::Duration::from_secs(1));
println!("I'm done.");
},
ok::<_,u8>(3u16) ?> |_| {
println!("Hello from parallel world again!");
// !!! Don't use std::thread::sleep to wait inside future because it will block executor thread !!!
// It's used here only to show that futures are executed on multi thread executor.
::std::thread::sleep(::std::time::Duration::from_secs(2));
println!("Me too.");
},
ok::<_,u8>(4u16),
map => |a, b, c| a * b * c
}.await.unwrap();
assert_eq!(product, 48);
}