about summary refs log tree commit diff
path: root/src/libstd/thread.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-12-23 11:53:35 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-12-29 12:16:49 -0800
commitbc83a009f655dd3896be4a7cd33cac8032a605f2 (patch)
tree3acc8533031219690fe14fa56f4427cfa9297296 /src/libstd/thread.rs
parentbb8f4fc3b73918abd19d67be702f78e8f73d1874 (diff)
downloadrust-bc83a009f655dd3896be4a7cd33cac8032a605f2.tar.gz
rust-bc83a009f655dd3896be4a7cd33cac8032a605f2.zip
std: Second pass stabilization for `comm`
This commit is a second pass stabilization for the `std::comm` module,
performing the following actions:

* The entire `std::comm` module was moved under `std::sync::mpsc`. This movement
  reflects that channels are just yet another synchronization primitive, and
  they don't necessarily deserve a special place outside of the other
  concurrency primitives that the standard library offers.
* The `send` and `recv` methods have all been removed.
* The `send_opt` and `recv_opt` methods have been renamed to `send` and `recv`.
  This means that all send/receive operations return a `Result` now indicating
  whether the operation was successful or not.
* The error type of `send` is now a `SendError` to implement a custom error
  message and allow for `unwrap()`. The error type contains an `into_inner`
  method to extract the value.
* The error type of `recv` is now `RecvError` for the same reasons as `send`.
* The `TryRecvError` and `TrySendError` types have had public reexports removed
  of their variants and the variant names have been tweaked with enum
  namespacing rules.
* The `Messages` iterator is renamed to `Iter`

This functionality is now all `#[stable]`:

* `Sender`
* `SyncSender`
* `Receiver`
* `std::sync::mpsc`
* `channel`
* `sync_channel`
* `Iter`
* `Sender::send`
* `Sender::clone`
* `SyncSender::send`
* `SyncSender::try_send`
* `SyncSender::clone`
* `Receiver::recv`
* `Receiver::try_recv`
* `Receiver::iter`
* `SendError`
* `RecvError`
* `TrySendError::{mod, Full, Disconnected}`
* `TryRecvError::{mod, Empty, Disconnected}`
* `SendError::into_inner`
* `TrySendError::into_inner`

This is a breaking change due to the modification of where this module is
located, as well as the changing of the semantics of `send` and `recv`. Most
programs just need to rename imports of `std::comm` to `std::sync::mpsc` and
add calls to `unwrap` after a send or a receive operation.

[breaking-change]
Diffstat (limited to 'src/libstd/thread.rs')
-rw-r--r--src/libstd/thread.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs
index fdf2648faa1..5c9e6153afb 100644
--- a/src/libstd/thread.rs
+++ b/src/libstd/thread.rs
@@ -443,7 +443,7 @@ mod test {
 
     use any::{Any, AnyRefExt};
     use boxed::BoxAny;
-    use comm::{channel, Sender};
+    use sync::mpsc::{channel, Sender};
     use result;
     use std::io::{ChanReader, ChanWriter};
     use super::{Thread, Builder};
@@ -470,9 +470,9 @@ mod test {
     fn test_run_basic() {
         let (tx, rx) = channel();
         Thread::spawn(move|| {
-            tx.send(());
+            tx.send(()).unwrap();
         }).detach();
-        rx.recv();
+        rx.recv().unwrap();
     }
 
     #[test]
@@ -505,7 +505,7 @@ mod test {
             let tx = tx.clone();
             Thread::spawn(move|| {
                 if i == 0 {
-                    tx.send(());
+                    tx.send(()).unwrap();
                 } else {
                     f(i - 1, tx);
                 }
@@ -513,7 +513,7 @@ mod test {
 
         }
         f(10, tx);
-        rx.recv();
+        rx.recv().unwrap();
     }
 
     #[test]
@@ -522,11 +522,11 @@ mod test {
 
         Thread::spawn(move|| {
             Thread::spawn(move|| {
-                tx.send(());
+                tx.send(()).unwrap();
             }).detach();
         }).detach();
 
-        rx.recv();
+        rx.recv().unwrap();
     }
 
     fn avoid_copying_the_body<F>(spawnfn: F) where F: FnOnce(Thunk) {
@@ -537,10 +537,10 @@ mod test {
 
         spawnfn(Thunk::new(move|| {
             let x_in_child = (&*x) as *const int as uint;
-            tx.send(x_in_child);
+            tx.send(x_in_child).unwrap();
         }));
 
-        let x_in_child = rx.recv();
+        let x_in_child = rx.recv().unwrap();
         assert_eq!(x_in_parent, x_in_child);
     }