Skip to content

Commit fabea18

Browse files
committed
doc test: fix mpsc.rs try_send doc test
1 parent a153133 commit fabea18

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

library/std/src/sync/mpsc.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,14 +697,14 @@ impl<T> SyncSender<T> {
697697
/// let sync_sender2 = sync_sender.clone();
698698
///
699699
/// // First thread owns sync_sender
700-
/// thread::spawn(move || {
700+
/// let handle1 = thread::spawn(move || {
701701
/// sync_sender.send(1).unwrap();
702702
/// sync_sender.send(2).unwrap();
703703
/// // Thread blocked
704704
/// });
705705
///
706706
/// // Second thread owns sync_sender2
707-
/// thread::spawn(move || {
707+
/// let handle2 = thread::spawn(move || {
708708
/// // This will return an error and send
709709
/// // no message if the buffer is full
710710
/// let _ = sync_sender2.try_send(3);
@@ -722,6 +722,10 @@ impl<T> SyncSender<T> {
722722
/// Ok(msg) => println!("message {msg} received"),
723723
/// Err(_) => println!("the third message was never sent"),
724724
/// }
725+
///
726+
/// // Wait for threads to complete
727+
/// handle1.join().unwrap();
728+
/// handle2.join().unwrap();
725729
/// ```
726730
#[stable(feature = "rust1", since = "1.0.0")]
727731
pub fn try_send(&self, t: T) -> Result<(), TrySendError<T>> {

0 commit comments

Comments
 (0)