Macro select

Source
select!() { /* proc-macro */ }
Expand description

Select the first future that completes (biased by order).

This macro is powered by the futures crate and is not bound to a particular executor or context.

§Fusing

This macro handles both the fusing and pinning of (fused) futures in a select-specific scope.

§Example

use std::time::Duration;
use commonware_macros::select;
use futures::executor::block_on;
use futures_timer::Delay;

async fn task() -> usize {
    42
}
block_on(async move {
    select! {
        _ = Delay::new(Duration::from_secs(1)) => {
            println!("timeout fired");
        },
        v = task() => {
            println!("task completed with value: {}", v);
        },
    };
});