[][src]Macro async_macros::try_select

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

Waits for either one of several similarly-typed futures to complete.

Awaits multiple futures simultaneously, returning all results once complete.

try_select! is similar to select!, but keeps going if a future resolved to an error until all futures have been resolved. In which case the error of the last item in the list will be returned.

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

Examples

use async_macros::try_select;
use futures::future;
use std::io::{Error, ErrorKind};

let a = future::pending::<Result<_, Error>>();
let b = future::ready(Err(Error::from(ErrorKind::Other)));
let c = future::ready(Ok(1u8));

assert_eq!(try_select!(a, b, c).await?, 1u8);