Skip to content

Commit

Permalink
Improve example for TryStreamExt::try_flatten. (#2540)
Browse files Browse the repository at this point in the history
The previous example was confusing because it didn't show what happened to `Err(4)`. I also added some more examples to show that entries after `Err(_)` are preserved.
  • Loading branch information
kevincox committed Dec 30, 2021
1 parent dacf256 commit 5406a5e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion futures-util/src/stream/try_stream/mod.rs
Expand Up @@ -653,17 +653,21 @@ pub trait TryStreamExt: TryStream {
/// thread::spawn(move || {
/// tx2.unbounded_send(Ok(2)).unwrap();
/// tx2.unbounded_send(Err(3)).unwrap();
/// tx2.unbounded_send(Ok(4)).unwrap();
/// });
/// thread::spawn(move || {
/// tx3.unbounded_send(Ok(rx1)).unwrap();
/// tx3.unbounded_send(Ok(rx2)).unwrap();
/// tx3.unbounded_send(Err(4)).unwrap();
/// tx3.unbounded_send(Err(5)).unwrap();
/// });
///
/// let mut stream = rx3.try_flatten();
/// assert_eq!(stream.next().await, Some(Ok(1)));
/// assert_eq!(stream.next().await, Some(Ok(2)));
/// assert_eq!(stream.next().await, Some(Err(3)));
/// assert_eq!(stream.next().await, Some(Ok(4)));
/// assert_eq!(stream.next().await, Some(Err(5)));
/// assert_eq!(stream.next().await, None);
/// # });
/// ```
fn try_flatten(self) -> TryFlatten<Self>
Expand Down

0 comments on commit 5406a5e

Please sign in to comment.