pub fn race_with_seed<T, F1, F2>(
    future1: F1,
    future2: F2,
    seed: u64
) -> Race<F1, F2> 
where F1: Future<Output = T>, F2: Future<Output = T>,
Expand description

Race two futures but with a predefined random seed.

This function is identical to race, but instead of using a random seed from a thread-local RNG, it allows the user to provide a seed. It is useful for when you already have a source of randomness available, or if you want to use a fixed seed.

See documentation of the race function for features and caveats.

Examples

use futures_lite::future::{self, pending, ready};

// A fixed seed is used, so the result is deterministic.
const SEED: u64 = 0x42;

assert_eq!(future::race_with_seed(ready(1), pending(), SEED).await, 1);
assert_eq!(future::race_with_seed(pending(), ready(2), SEED).await, 2);

// One of the two futures is randomly chosen as the winner.
let res = future::race_with_seed(ready(1), ready(2), SEED).await;