Function futures_lite::stream::race_with_seed

source ·
pub fn race_with_seed<T, S1, S2>(
    stream1: S1,
    stream2: S2,
    seed: u64,
) -> Race<S1, S2>
where S1: Stream<Item = T>, S2: Stream<Item = T>,
Expand description

Races two streams, but with a user-provided seed for randomness.

§Examples

use futures_lite::stream::{self, once, pending, StreamExt};

// A fixed seed is used for reproducibility.
const SEED: u64 = 123;

assert_eq!(stream::race_with_seed(once(1), pending(), SEED).next().await, Some(1));
assert_eq!(stream::race_with_seed(pending(), once(2), SEED).next().await, Some(2));

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