[−][src]Function smol::future::race
pub fn race<T, F1, F2>(future1: F1, future2: F2) -> Race<F1, F2>ⓘ where
F1: Future<Output = T>,
F2: Future<Output = T>,
Returns the result of the future that completes first, with no preference if both are ready.
Each time Race
is polled, the two inner futures are polled in random order. Therefore, no
future takes precedence over the other if both can complete at the same time.
If you have prec for one of the futures, use the or()
method
instead.
Examples
use futures_lite::future::{pending, race, ready}; assert_eq!(race(ready(1), pending()).await, 1); assert_eq!(race(pending(), ready(2)).await, 2); // One of the two futures is randomly chosen as the winner. let res = race(ready(1), ready(2)).await;