Function futures_lite::future::or [−][src]
pub fn or<T, F1, F2>(future1: F1, future2: F2) -> Or<F1, F2>ⓘ where
F1: Future<Output = T>,
F2: Future<Output = T>,
Returns the result of the future that completes first, preferring future1
if both are ready.
If you need to treat the two futures fairly without a preference for either, use the race()
function or the FutureExt::race()
method.
Examples
use futures_lite::future::{self, pending, ready}; assert_eq!(future::or(ready(1), pending()).await, 1); assert_eq!(future::or(pending(), ready(2)).await, 2); // The first future wins. assert_eq!(future::or(ready(1), ready(2)).await, 1);