From bc83a009f655dd3896be4a7cd33cac8032a605f2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 23 Dec 2014 11:53:35 -0800 Subject: 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] --- src/libstd/sync/task_pool.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/libstd/sync/task_pool.rs') diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index ce7e883e803..b0325998358 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -12,9 +12,9 @@ use core::prelude::*; -use thread::Thread; -use comm::{channel, Sender, Receiver}; use sync::{Arc, Mutex}; +use sync::mpsc::{channel, Sender, Receiver}; +use thread::Thread; use thunk::Thunk; struct Sentinel<'a> { @@ -55,7 +55,7 @@ impl<'a> Drop for Sentinel<'a> { /// ```rust /// use std::sync::TaskPool; /// use std::iter::AdditiveIterator; -/// use std::comm::channel; +/// use std::sync::mpsc::channel; /// /// let pool = TaskPool::new(4u); /// @@ -63,7 +63,7 @@ impl<'a> Drop for Sentinel<'a> { /// for _ in range(0, 8u) { /// let tx = tx.clone(); /// pool.execute(move|| { -/// tx.send(1u); +/// tx.send(1u).unwrap(); /// }); /// } /// @@ -101,7 +101,7 @@ impl TaskPool { pub fn execute(&self, job: F) where F : FnOnce(), F : Send { - self.jobs.send(Thunk::new(job)); + self.jobs.send(Thunk::new(job)).unwrap(); } } @@ -115,7 +115,7 @@ fn spawn_in_pool(jobs: Arc>>) { // Only lock jobs for the time it takes // to get a job, not run it. let lock = jobs.lock(); - lock.recv_opt() + lock.recv() }; match message { @@ -134,7 +134,7 @@ fn spawn_in_pool(jobs: Arc>>) { mod test { use prelude::v1::*; use super::*; - use comm::channel; + use sync::mpsc::channel; const TEST_TASKS: uint = 4u; @@ -148,7 +148,7 @@ mod test { for _ in range(0, TEST_TASKS) { let tx = tx.clone(); pool.execute(move|| { - tx.send(1u); + tx.send(1u).unwrap(); }); } @@ -177,7 +177,7 @@ mod test { for _ in range(0, TEST_TASKS) { let tx = tx.clone(); pool.execute(move|| { - tx.send(1u); + tx.send(1u).unwrap(); }); } -- cgit 1.4.1-3-g733a5