Function flo_stream::generator_stream[][src]

pub fn generator_stream<'a, TItem, TFuture, TFutureFn: FnOnce(Box<dyn Send + Sync + Fn(TItem) -> BoxFuture<'static, ()> + 'a>) -> TFuture>(
    start_future: TFutureFn
) -> impl Stream<Item = TItem> where
    TItem: 'a + Send,
    TFuture: 'a + Future<Output = ()>, 

Creates a new generator stream: this is a stream where the items are generated by a future, which can yield them to be returned by the stream via the function that's passed in. This is useful for cases where a stream's values are generated by complicated, stateful behaviour.

For example, here is a simple generator stream that produces the sequence '0, 1, 2':

let mut generated_stream = generator_stream(|yield_value| async move {
   for num in 0u32..3 {
       yield_value(num).await;
   }
});