[][src]Function futures_lite::future::race

pub fn race<T, A, B>(future1: A, future2: B) -> Race<A, B>

Important traits for Race<A, B>

impl<T, A, B> Future for Race<A, B> where
    A: Future<Output = T>,
    B: Future<Output = T>, 
type Output = T;
where
    A: Future<Output = T>,
    B: 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;