select!() { /* proc-macro */ }
Expand description
Select the first future that completes (biased by order).
This macro is powered by the futures::select_biased!
macro
and as such is not bound to a particular executor or runtime.
ยงExample
use std::time::Duration;
use commonware_macros::select;
use commonware_runtime::{Clock, Spawner, Runner, deterministic::{Executor, Config}};
async fn task() -> usize {
42
}
let (executor, runtime, auditor) = Executor::default();
executor.start(async move {
select! {
_ = runtime.sleep(Duration::from_secs(1)) => {
println!("timeout fired");
},
v = task() => {
println!("task completed with value: {}", v);
},
};
});