Skip to content

Commit 5406a5e

Browse files
authored
Improve example for TryStreamExt::try_flatten. (#2540)
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.
1 parent dacf256 commit 5406a5e

File tree

1 file changed

+5
-1
lines changed
  • futures-util/src/stream/try_stream

1 file changed

+5
-1
lines changed

futures-util/src/stream/try_stream/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,17 +653,21 @@ pub trait TryStreamExt: TryStream {
653653
/// thread::spawn(move || {
654654
/// tx2.unbounded_send(Ok(2)).unwrap();
655655
/// tx2.unbounded_send(Err(3)).unwrap();
656+
/// tx2.unbounded_send(Ok(4)).unwrap();
656657
/// });
657658
/// thread::spawn(move || {
658659
/// tx3.unbounded_send(Ok(rx1)).unwrap();
659660
/// tx3.unbounded_send(Ok(rx2)).unwrap();
660-
/// tx3.unbounded_send(Err(4)).unwrap();
661+
/// tx3.unbounded_send(Err(5)).unwrap();
661662
/// });
662663
///
663664
/// let mut stream = rx3.try_flatten();
664665
/// assert_eq!(stream.next().await, Some(Ok(1)));
665666
/// assert_eq!(stream.next().await, Some(Ok(2)));
666667
/// assert_eq!(stream.next().await, Some(Err(3)));
668+
/// assert_eq!(stream.next().await, Some(Ok(4)));
669+
/// assert_eq!(stream.next().await, Some(Err(5)));
670+
/// assert_eq!(stream.next().await, None);
667671
/// # });
668672
/// ```
669673
fn try_flatten(self) -> TryFlatten<Self>

0 commit comments

Comments
 (0)