[−][src]Function async_std::stream::repeat_with
pub fn repeat_with<F, Fut, A>(repeater: F) -> RepeatWith<F, Fut, A> where
F: FnMut() -> Fut,
Fut: Future<Output = A>,
Creates a new stream that repeats elements of type A
endlessly by applying the provided closure.
Examples
Basic usage:
use async_std::prelude::*; use async_std::stream; let s = stream::repeat_with(|| async { 1 }); pin_utils::pin_mut!(s); assert_eq!(s.next().await, Some(1)); assert_eq!(s.next().await, Some(1)); assert_eq!(s.next().await, Some(1)); assert_eq!(s.next().await, Some(1));
Going finite:
use async_std::prelude::*; use async_std::stream; let s = stream::repeat_with(|| async { 1u8 }).take(2); pin_utils::pin_mut!(s); assert_eq!(s.next().await, Some(1)); assert_eq!(s.next().await, Some(1)); assert_eq!(s.next().await, None);