diff options
| author | Eval EXEC <execvy@gmail.com> | 2025-08-12 18:36:16 +0800 |
|---|---|---|
| committer | Eval EXEC <execvy@gmail.com> | 2025-08-13 21:09:32 +0800 |
| commit | a0eea23317e60ef1b648abd0fe76ca89362ac44d (patch) | |
| tree | a1be879ae797c20b2405daf488831cf92b0367da /library/std/src | |
| parent | a1531335fe2807715fff569904d99602022643a7 (diff) | |
| download | rust-a0eea23317e60ef1b648abd0fe76ca89362ac44d.tar.gz rust-a0eea23317e60ef1b648abd0fe76ca89362ac44d.zip | |
doc test: fix mpsc.rs try_send doc test
Signed-off-by: Eval EXEC <execvy@gmail.com>
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/sync/mpsc.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/library/std/src/sync/mpsc.rs b/library/std/src/sync/mpsc.rs index 41d1dd3ce67..03d7fddc2fa 100644 --- a/library/std/src/sync/mpsc.rs +++ b/library/std/src/sync/mpsc.rs @@ -697,14 +697,14 @@ impl<T> SyncSender<T> { /// let sync_sender2 = sync_sender.clone(); /// /// // First thread owns sync_sender - /// thread::spawn(move || { + /// let handle1 = thread::spawn(move || { /// sync_sender.send(1).unwrap(); /// sync_sender.send(2).unwrap(); /// // Thread blocked /// }); /// /// // Second thread owns sync_sender2 - /// thread::spawn(move || { + /// let handle2 = thread::spawn(move || { /// // This will return an error and send /// // no message if the buffer is full /// let _ = sync_sender2.try_send(3); @@ -722,6 +722,10 @@ impl<T> SyncSender<T> { /// Ok(msg) => println!("message {msg} received"), /// Err(_) => println!("the third message was never sent"), /// } + /// + /// // Wait for threads to complete + /// handle1.join().unwrap(); + /// handle2.join().unwrap(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn try_send(&self, t: T) -> Result<(), TrySendError<T>> { |
