[][src]Macro async_std::future::try_join

macro_rules! try_join {
    ($ ($ fut : ident), * $ (,) ?) => { ... };
}

Awaits multiple fallible futures simultaneously, returning all results once complete.

try_join! is similar to [join!], but completes immediately if any of the futures return an error.

This macro is only usable inside of async functions, closures, and blocks.

Examples

When used on multiple futures that return Ok, try_join! will return Ok of a tuple of the values:

#![feature(async_await)]
use async_macros::try_join;
use futures::future;

let a = future::ready(Ok::<i32, i32>(1));
let b = future::ready(Ok::<u64, i32>(2));

assert_eq!(try_join!(a, b).await, Ok((1, 2)));

If one of the futures resolves to an error, try_join! will return that error:

#![feature(async_await)]
use async_macros::try_join;
use futures::future;

let a = future::ready(Ok::<i32, i32>(1));
let b = future::ready(Err::<u64, i32>(2));

assert_eq!(try_join!(a, b).await, Err(2));