summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-07-20 12:01:31 +0000
committerbors <bors@rust-lang.org>2014-07-20 12:01:31 +0000
commite6b28f9ac3f6a1a6441e0d47c56c660d7a10abf9 (patch)
tree53b0fb06db65591df1f878f8de78236521ef018c /src/libstd
parent343a52f6b5e567516abeb2af500ed8933dcb6085 (diff)
parent0b946f0a9099c8a116d2f51473a48d0e16b43037 (diff)
downloadrust-e6b28f9ac3f6a1a6441e0d47c56c660d7a10abf9.tar.gz
rust-e6b28f9ac3f6a1a6441e0d47c56c660d7a10abf9.zip
auto merge of #15797 : brson/rust/taskstab, r=alexcrichton
Summary:

* alloc::rc module stable
* Rc type stable
* Functions relating to weak references experimental
* core::cmp module stable
* PartialEq/Eq/PartialOrd/Ord unstable because trait reform will make them change again
* Equiv experimental because there may be better sol'ns
* lexical_ordering deprecated because it can be done trivially with the Ord trait
* min/max stable
* std::task module stable
* TaskBuilder::stdout/stderr experimental because we aren't certain we want to configure the environment this way
* try_future experimental because Future is experimental
* try unstable because the error type might change
* deschedule/failing unstable

The major thing I did differently than previously-discussed is that I made `try` experimental: there's been discussion that the error type `Box<Any + Send>` is not sufficient.


Per https://github.com/rust-lang/meeting-minutes/blob/master/Meeting-API-review-2014-07-16.md.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/task.rs59
1 files changed, 37 insertions, 22 deletions
diff --git a/src/libstd/task.rs b/src/libstd/task.rs
index d7af92024eb..4b8c15a0152 100644
--- a/src/libstd/task.rs
+++ b/src/libstd/task.rs
@@ -91,7 +91,7 @@
 //! # }
 //! ```
 
-#![experimental]
+#![stable]
 
 use any::Any;
 use comm::channel;
@@ -104,7 +104,9 @@ use rt::local::Local;
 use rt::task;
 use rt::task::Task;
 use str::{Str, SendStr, IntoMaybeOwned};
+use string::String;
 use sync::Future;
+use to_str::ToString;
 
 /// A means of spawning a task
 pub trait Spawner {
@@ -172,6 +174,7 @@ impl TaskBuilder<SiblingSpawner> {
 impl<S: Spawner> TaskBuilder<S> {
     /// Name the task-to-be. Currently the name is used for identification
     /// only in failure messages.
+    #[unstable = "IntoMaybeOwned will probably change."]
     pub fn named<T: IntoMaybeOwned<'static>>(mut self, name: T) -> TaskBuilder<S> {
         self.name = Some(name.into_maybe_owned());
         self
@@ -184,12 +187,14 @@ impl<S: Spawner> TaskBuilder<S> {
     }
 
     /// Redirect task-local stdout.
+    #[experimental = "May not want to make stdio overridable here."]
     pub fn stdout(mut self, stdout: Box<Writer + Send>) -> TaskBuilder<S> {
         self.stdout = Some(stdout);
         self
     }
 
     /// Redirect task-local stderr.
+    #[experimental = "May not want to make stdio overridable here."]
     pub fn stderr(mut self, stderr: Box<Writer + Send>) -> TaskBuilder<S> {
         self.stderr = Some(stderr);
         self
@@ -288,6 +293,7 @@ impl<S: Spawner> TaskBuilder<S> {
     /// future returns `result::Ok` containing the value returned by the
     /// function. If the child task fails then the future returns `result::Err`
     /// containing the argument to `fail!(...)` as an `Any` trait object.
+    #[experimental = "Futures are experimental."]
     pub fn try_future<T:Send>(self, f: proc():Send -> T)
                               -> Future<Result<T, Box<Any + Send>>> {
         // currently, the on_exit proc provided by librustrt only works for unit
@@ -308,6 +314,7 @@ impl<S: Spawner> TaskBuilder<S> {
 
     /// Execute a function in a newly-spawnedtask and block until the task
     /// completes or fails. Equivalent to `.try_future(f).unwrap()`.
+    #[unstable = "Error type may change."]
     pub fn try<T:Send>(self, f: proc():Send -> T) -> Result<T, Box<Any + Send>> {
         self.try_future(f).unwrap()
     }
@@ -329,6 +336,7 @@ pub fn spawn(f: proc(): Send) {
 /// value of the function or an error if the task failed.
 ///
 /// This is equivalent to `TaskBuilder::new().try`.
+#[unstable = "Error type may change."]
 pub fn try<T: Send>(f: proc(): Send -> T) -> Result<T, Box<Any + Send>> {
     TaskBuilder::new().try(f)
 }
@@ -337,6 +345,7 @@ pub fn try<T: Send>(f: proc(): Send -> T) -> Result<T, Box<Any + Send>> {
 /// task's result.
 ///
 /// This is equivalent to `TaskBuilder::new().try_future`.
+#[experimental = "Futures are experimental."]
 pub fn try_future<T:Send>(f: proc():Send -> T) -> Future<Result<T, Box<Any + Send>>> {
     TaskBuilder::new().try_future(f)
 }
@@ -345,6 +354,7 @@ pub fn try_future<T:Send>(f: proc():Send -> T) -> Future<Result<T, Box<Any + Sen
 /* Lifecycle functions */
 
 /// Read the name of the current task.
+#[deprecated = "Use `task::name()`."]
 pub fn with_task_name<U>(blk: |Option<&str>| -> U) -> U {
     use rt::task::Task;
 
@@ -355,7 +365,20 @@ pub fn with_task_name<U>(blk: |Option<&str>| -> U) -> U {
     }
 }
 
+/// Read the name of the current task.
+#[stable]
+pub fn name() -> Option<String> {
+    use rt::task::Task;
+
+    let task = Local::borrow(None::<Task>);
+    match task.name {
+        Some(ref name) => Some(name.as_slice().to_string()),
+        None => None
+    }
+}
+
 /// Yield control to the task scheduler.
+#[unstable = "Name will change."]
 pub fn deschedule() {
     use rt::local::Local;
 
@@ -366,6 +389,7 @@ pub fn deschedule() {
 
 /// True if the running task is currently failing (e.g. will return `true` inside a
 /// destructor that is run while unwinding the stack after a call to `fail!()`).
+#[unstable = "May move to a different module."]
 pub fn failing() -> bool {
     use rt::task::Task;
     Local::borrow(None::<Task>).unwinder.unwinding()
@@ -377,7 +401,6 @@ mod test {
     use boxed::BoxAny;
     use result;
     use result::{Ok, Err};
-    use str::StrAllocating;
     use string::String;
     use std::io::{ChanReader, ChanWriter};
     use prelude::*;
@@ -388,38 +411,30 @@ mod test {
 
     #[test]
     fn test_unnamed_task() {
-        spawn(proc() {
-            with_task_name(|name| {
-                assert!(name.is_none());
-            })
-        })
+        try(proc() {
+            assert!(name().is_none());
+        }).map_err(|_| ()).unwrap();
     }
 
     #[test]
     fn test_owned_named_task() {
-        TaskBuilder::new().named("ada lovelace".to_string()).spawn(proc() {
-            with_task_name(|name| {
-                assert!(name.unwrap() == "ada lovelace");
-            })
-        })
+        TaskBuilder::new().named("ada lovelace".to_string()).try(proc() {
+            assert!(name().unwrap() == "ada lovelace".to_string());
+        }).map_err(|_| ()).unwrap();
     }
 
     #[test]
     fn test_static_named_task() {
-        TaskBuilder::new().named("ada lovelace").spawn(proc() {
-            with_task_name(|name| {
-                assert!(name.unwrap() == "ada lovelace");
-            })
-        })
+        TaskBuilder::new().named("ada lovelace").try(proc() {
+            assert!(name().unwrap() == "ada lovelace".to_string());
+        }).map_err(|_| ()).unwrap();
     }
 
     #[test]
     fn test_send_named_task() {
-        TaskBuilder::new().named("ada lovelace".into_maybe_owned()).spawn(proc() {
-            with_task_name(|name| {
-                assert!(name.unwrap() == "ada lovelace");
-            })
-        })
+        TaskBuilder::new().named("ada lovelace".into_maybe_owned()).try(proc() {
+            assert!(name().unwrap() == "ada lovelace".to_string());
+        }).map_err(|_| ()).unwrap();
     }
 
     #[test]