macro_rules! race {
(biased; $($future:expr),+ $(,)?) => { ... };
($($future:expr),+ $(,)?) => { ... };
}Expand description
Macro for racing multiple futures.
The first future to complete wins.
Note: this macro is currently a placeholder and does not implement the
full asupersync race semantics (cancel + drain losers). Use the Scope
APIs (Scope::race, Scope::race_all) when racing spawned tasks.
§Basic Usage
ⓘ
let winner: Race2<A, B> = race!(fut_a, fut_b).await;
let winner: Race3<A, B, C> = race!(fut_a, fut_b, fut_c).await;§Biased Mode
Use biased; for left-to-right polling priority (useful for fallback patterns):
ⓘ
race! { biased;
check_cache(key),
query_database(key),
}§Key Properties
- First future to return
Poll::Readyis the winner - All non-winning futures go through the cancellation protocol
race!waits for all losers to complete before returning- Losers complete with
Outcome::Cancelled(RaceLost)