Skip to content

Commit 8603348

Browse files
kevincoxtaiki-e
authored andcommitted
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 29a736f commit 8603348

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
@@ -736,17 +736,21 @@ pub trait TryStreamExt: TryStream {
736736
/// thread::spawn(move || {
737737
/// tx2.unbounded_send(Ok(2)).unwrap();
738738
/// tx2.unbounded_send(Err(3)).unwrap();
739+
/// tx2.unbounded_send(Ok(4)).unwrap();
739740
/// });
740741
/// thread::spawn(move || {
741742
/// tx3.unbounded_send(Ok(rx1)).unwrap();
742743
/// tx3.unbounded_send(Ok(rx2)).unwrap();
743-
/// tx3.unbounded_send(Err(4)).unwrap();
744+
/// tx3.unbounded_send(Err(5)).unwrap();
744745
/// });
745746
///
746747
/// let mut stream = rx3.try_flatten();
747748
/// assert_eq!(stream.next().await, Some(Ok(1)));
748749
/// assert_eq!(stream.next().await, Some(Ok(2)));
749750
/// assert_eq!(stream.next().await, Some(Err(3)));
751+
/// assert_eq!(stream.next().await, Some(Ok(4)));
752+
/// assert_eq!(stream.next().await, Some(Err(5)));
753+
/// assert_eq!(stream.next().await, None);
750754
/// # });
751755
/// ```
752756
fn try_flatten(self) -> TryFlatten<Self>

0 commit comments

Comments
 (0)