[][src]Function futures_util::try_future::try_join

Important traits for TryJoin<Fut1, Fut2>
pub fn try_join<Fut1, Fut2>(future1: Fut1, future2: Fut2) -> TryJoin<Fut1, Fut2> where
    Fut1: TryFuture,
    Fut2: TryFuture<Error = Fut1::Error>, 

Joins the result of two futures, waiting for them both to complete or for one to produce an error.

This function will return a new future which awaits both futures to complete. If successful, the returned future will finish with a tuple of both results. If unsuccesful, it will complete with the first error encountered.

Note that this function consumes the passed futures and returns a wrapped version of it.

Examples

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

#![feature(async_await, await_macro)]
use futures::future;

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

assert_eq!(await!(pair), Ok((1, 2)));

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

#![feature(async_await, await_macro)]
use futures::future;

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

assert_eq!(await!(pair), Err(2));