[][src]Macro async_macros::select

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

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

Awaits multiple futures simultaneously, returning all results once complete.

This function will return a new future which awaits for either one of both futures to complete. If multiple futures are completed at the same time, resolution will occur in the order that they have been passed.

Note that this macro consumes all futures passed, and once a future is completed, all other futures are dropped.

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

Examples

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

let a = future::pending();
let b = future::ready(1u8);
let c = future::ready(2u8);

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