Macro zng::task::any_some

source ·
macro_rules! any_some {
    ($fut0:expr $(,)?) => { ... };
    ($fut0:expr, $fut1:expr $(,)?) => { ... };
    ($fut0:expr, $fut1:expr, $fut2:expr $(,)?) => { ... };
    ($fut0:expr, $fut1:expr, $fut2:expr, $fut3:expr $(,)?) => { ... };
    ($fut0:expr, $fut1:expr, $fut2:expr, $fut3:expr, $fut4:expr $(,)?) => { ... };
    ($fut0:expr, $fut1:expr, $fut2:expr, $fut3:expr, $fut4:expr, $fut5:expr $(,)?) => { ... };
    ($fut0:expr, $fut1:expr, $fut2:expr, $fut3:expr, $fut4:expr, $fut5:expr, $fut6:expr $(,)?) => { ... };
    ($fut0:expr, $fut1:expr, $fut2:expr, $fut3:expr, $fut4:expr, $fut5:expr, $fut6:expr, $fut7:expr $(,)?) => { ... };
    ($($fut:expr),+ $(,)?) => { ... };
}
Expand description

A future that is ready when any of the futures is ready and Some(T).

The macro input is comma separated list of future expressions, the futures must all have the same output Option<T> type. The macro output is a future that when “.awaited” produces a single output type instance returned by the first input future that completes with a Some. If all futures complete with a None the output is None.

At least one input future is required and any number of futures is accepted. For more than eight futures a proc-macro is used which may cause code auto-complete to stop working in some IDEs.

If two futures are ready and Some(T) at the same time the result of the first future in the input list is used. After one future is ready and Some(T) the other futures are not polled again and are dropped. After a future is ready and None it is also not polled again and dropped.

§Examples

Await for the first of three futures to complete with Some:

use zng_task as task;
let r = task::any_some!(
    task::run(async { None::<char> }),
    task::wait(|| Some('b')),
    async { None::<char> }
).await;

assert_eq!(Some('b'), r);