Function bevy::tasks::futures_lite::stream::race_with_seed

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>,
Available on crate feature race only.
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;