[][src]Macro join::try_join_async_spawn

macro_rules! try_join_async_spawn {
    #[proc_macro_hack(support_nested, internal_macro_calls = 20)] => { ... };
}

Use to spawn ::tokio::spawn per each step of each branch. It transposes tuple of Results into Result of tuple or single Result in case of 1 branch.

#![recursion_limit="512"]

extern crate join;
extern crate futures;
extern crate tokio;
extern crate futures_timer;

use join::try_join_async_spawn;
use futures::future::ok;
use futures_timer::Delay;
use std::time::Duration;

#[tokio::main]
async fn main() {
    let product = try_join_async_spawn! {
        ok::<_,u8>(2u16) |> |v| Ok::<_,u8>(v.unwrap() + 2u16) => |v| async move {
            println!("Hello from parallel world!");
            Delay::new(Duration::from_secs(1)).await.unwrap();
            println!("I'm done.");
            Ok(v)
        },
        ok::<_,u8>(3u16) => |v| async move {
            println!("Hello from parallel world again!");
            Delay::new(Duration::from_secs(2)).await.unwrap();
            println!("Me too.");
            Ok(v)
        },
        ok::<_,u8>(4u16),
        map => |a, b, c| a * b * c
    }.await.unwrap();

    assert_eq!(product, 48);
}