9191//! # }
9292//! ```
9393
94- #![ experimental ]
94+ #![ stable ]
9595
9696use any:: Any ;
9797use comm:: channel;
@@ -104,7 +104,9 @@ use rt::local::Local;
104104use rt:: task;
105105use rt:: task:: Task ;
106106use str:: { Str , SendStr , IntoMaybeOwned } ;
107+ use string:: String ;
107108use sync:: Future ;
109+ use to_str:: ToString ;
108110
109111/// A means of spawning a task
110112pub trait Spawner {
@@ -172,6 +174,7 @@ impl TaskBuilder<SiblingSpawner> {
172174impl < S : Spawner > TaskBuilder < S > {
173175 /// Name the task-to-be. Currently the name is used for identification
174176 /// only in failure messages.
177+ #[ unstable = "IntoMaybeOwned will probably change." ]
175178 pub fn named < T : IntoMaybeOwned < ' static > > ( mut self , name : T ) -> TaskBuilder < S > {
176179 self . name = Some ( name. into_maybe_owned ( ) ) ;
177180 self
@@ -184,12 +187,14 @@ impl<S: Spawner> TaskBuilder<S> {
184187 }
185188
186189 /// Redirect task-local stdout.
190+ #[ experimental = "May not want to make stdio overridable here." ]
187191 pub fn stdout ( mut self , stdout : Box < Writer + Send > ) -> TaskBuilder < S > {
188192 self . stdout = Some ( stdout) ;
189193 self
190194 }
191195
192196 /// Redirect task-local stderr.
197+ #[ experimental = "May not want to make stdio overridable here." ]
193198 pub fn stderr ( mut self , stderr : Box < Writer + Send > ) -> TaskBuilder < S > {
194199 self . stderr = Some ( stderr) ;
195200 self
@@ -288,6 +293,7 @@ impl<S: Spawner> TaskBuilder<S> {
288293 /// future returns `result::Ok` containing the value returned by the
289294 /// function. If the child task fails then the future returns `result::Err`
290295 /// containing the argument to `fail!(...)` as an `Any` trait object.
296+ #[ experimental = "Futures are experimental." ]
291297 pub fn try_future < T : Send > ( self , f : proc ( ) : Send -> T )
292298 -> Future < Result < T , Box < Any + Send > > > {
293299 // currently, the on_exit proc provided by librustrt only works for unit
@@ -308,6 +314,7 @@ impl<S: Spawner> TaskBuilder<S> {
308314
309315 /// Execute a function in a newly-spawnedtask and block until the task
310316 /// completes or fails. Equivalent to `.try_future(f).unwrap()`.
317+ #[ unstable = "Error type may change." ]
311318 pub fn try < T : Send > ( self , f : proc ( ) : Send -> T ) -> Result < T , Box < Any + Send > > {
312319 self . try_future ( f) . unwrap ( )
313320 }
@@ -329,6 +336,7 @@ pub fn spawn(f: proc(): Send) {
329336/// value of the function or an error if the task failed.
330337///
331338/// This is equivalent to `TaskBuilder::new().try`.
339+ #[ unstable = "Error type may change." ]
332340pub fn try < T : Send > ( f : proc ( ) : Send -> T ) -> Result < T , Box < Any + Send > > {
333341 TaskBuilder :: new ( ) . try ( f)
334342}
@@ -337,6 +345,7 @@ pub fn try<T: Send>(f: proc(): Send -> T) -> Result<T, Box<Any + Send>> {
337345/// task's result.
338346///
339347/// This is equivalent to `TaskBuilder::new().try_future`.
348+ #[ experimental = "Futures are experimental." ]
340349pub fn try_future < T : Send > ( f : proc ( ) : Send -> T ) -> Future < Result < T , Box < Any + Send > > > {
341350 TaskBuilder :: new ( ) . try_future ( f)
342351}
@@ -345,6 +354,7 @@ pub fn try_future<T:Send>(f: proc():Send -> T) -> Future<Result<T, Box<Any + Sen
345354/* Lifecycle functions */
346355
347356/// Read the name of the current task.
357+ #[ deprecated = "Use `task::name()`." ]
348358pub fn with_task_name < U > ( blk: |Option < & str > | -> U ) -> U {
349359 use rt:: task:: Task ;
350360
@@ -355,7 +365,20 @@ pub fn with_task_name<U>(blk: |Option<&str>| -> U) -> U {
355365 }
356366}
357367
368+ /// Read the name of the current task.
369+ #[ stable]
370+ pub fn name ( ) -> Option < String > {
371+ use rt:: task:: Task ;
372+
373+ let task = Local :: borrow ( None :: < Task > ) ;
374+ match task. name {
375+ Some ( ref name) => Some ( name. as_slice ( ) . to_string ( ) ) ,
376+ None => None
377+ }
378+ }
379+
358380/// Yield control to the task scheduler.
381+ #[ unstable = "Name will change." ]
359382pub fn deschedule ( ) {
360383 use rt:: local:: Local ;
361384
@@ -366,6 +389,7 @@ pub fn deschedule() {
366389
367390/// True if the running task is currently failing (e.g. will return `true` inside a
368391/// destructor that is run while unwinding the stack after a call to `fail!()`).
392+ #[ unstable = "May move to a different module." ]
369393pub fn failing ( ) -> bool {
370394 use rt:: task:: Task ;
371395 Local :: borrow ( None :: < Task > ) . unwinder . unwinding ( )
@@ -377,7 +401,6 @@ mod test {
377401 use boxed:: BoxAny ;
378402 use result;
379403 use result:: { Ok , Err } ;
380- use str:: StrAllocating ;
381404 use string:: String ;
382405 use std:: io:: { ChanReader , ChanWriter } ;
383406 use prelude:: * ;
@@ -388,38 +411,30 @@ mod test {
388411
389412 #[ test]
390413 fn test_unnamed_task ( ) {
391- spawn ( proc ( ) {
392- with_task_name ( |name| {
393- assert ! ( name. is_none( ) ) ;
394- } )
395- } )
414+ try( proc ( ) {
415+ assert ! ( name( ) . is_none( ) ) ;
416+ } ) . map_err ( |_| ( ) ) . unwrap ( ) ;
396417 }
397418
398419 #[ test]
399420 fn test_owned_named_task ( ) {
400- TaskBuilder :: new ( ) . named ( "ada lovelace" . to_string ( ) ) . spawn ( proc ( ) {
401- with_task_name ( |name| {
402- assert ! ( name. unwrap( ) == "ada lovelace" ) ;
403- } )
404- } )
421+ TaskBuilder :: new ( ) . named ( "ada lovelace" . to_string ( ) ) . try ( proc ( ) {
422+ assert ! ( name( ) . unwrap( ) == "ada lovelace" . to_string( ) ) ;
423+ } ) . map_err ( |_| ( ) ) . unwrap ( ) ;
405424 }
406425
407426 #[ test]
408427 fn test_static_named_task ( ) {
409- TaskBuilder :: new ( ) . named ( "ada lovelace" ) . spawn ( proc ( ) {
410- with_task_name ( |name| {
411- assert ! ( name. unwrap( ) == "ada lovelace" ) ;
412- } )
413- } )
428+ TaskBuilder :: new ( ) . named ( "ada lovelace" ) . try ( proc ( ) {
429+ assert ! ( name( ) . unwrap( ) == "ada lovelace" . to_string( ) ) ;
430+ } ) . map_err ( |_| ( ) ) . unwrap ( ) ;
414431 }
415432
416433 #[ test]
417434 fn test_send_named_task ( ) {
418- TaskBuilder :: new ( ) . named ( "ada lovelace" . into_maybe_owned ( ) ) . spawn ( proc ( ) {
419- with_task_name ( |name| {
420- assert ! ( name. unwrap( ) == "ada lovelace" ) ;
421- } )
422- } )
435+ TaskBuilder :: new ( ) . named ( "ada lovelace" . into_maybe_owned ( ) ) . try ( proc ( ) {
436+ assert ! ( name( ) . unwrap( ) == "ada lovelace" . to_string( ) ) ;
437+ } ) . map_err ( |_| ( ) ) . unwrap ( ) ;
423438 }
424439
425440 #[ test]
0 commit comments