Macro zng::task::all_some

source ·
macro_rules! all_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 all futures are ready with Some(T) or when any is future ready with None.

The macro input is comma separated list of future expressions, the futures must all have the Option<T> output type, but each can have a different T. The macro output is a future that when “.awaited” produces Some<(T0, T1, ..)> if all futures where Some(T) or None if any of the futures where 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.

After one future is ready and None the other futures are not polled again and are dropped. After a future is ready 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::all_some!(
    task::run(async { Some('a') }),
    task::wait(|| Some('b')),
    async { Some('c') }
).await;

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

Completes with None if any future completes with None:

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

assert_eq!(None, r);