@@ -91,19 +91,17 @@ pub struct TaskBuilder {
9191 nocopy : Option < marker:: NoCopy > ,
9292}
9393
94- /**
95- * Generate the base configuration for spawning a task, off of which more
96- * configuration methods can be chained.
97- */
98- pub fn task ( ) -> TaskBuilder {
99- TaskBuilder {
100- opts : TaskOpts :: new ( ) ,
101- gen_body : None ,
102- nocopy : None ,
94+ impl TaskBuilder {
95+ /// Generate the base configuration for spawning a task, off of which more
96+ /// configuration methods can be chained.
97+ pub fn new ( ) -> TaskBuilder {
98+ TaskBuilder {
99+ opts : TaskOpts :: new ( ) ,
100+ gen_body : None ,
101+ nocopy : None ,
102+ }
103103 }
104- }
105104
106- impl TaskBuilder {
107105 /// Get a future representing the exit status of the task.
108106 ///
109107 /// Taking the value of the future will block until the child task
@@ -233,22 +231,17 @@ impl TaskOpts {
233231/// Sets up a new task with its own call stack and schedules it to run
234232/// the provided unique closure.
235233///
236- /// This function is equivalent to `task ().spawn(f)`.
234+ /// This function is equivalent to `TaskBuilder::new ().spawn(f)`.
237235pub fn spawn ( f : proc ( ) : Send ) {
238- let task = task ( ) ;
239- task. spawn ( f)
236+ TaskBuilder :: new ( ) . spawn ( f)
240237}
241238
239+ /// Execute a function in another task and return either the return value of
240+ /// the function or an error if the task failed
241+ ///
242+ /// This is equivalent to TaskBuilder::new().try
242243pub fn try < T : Send > ( f : proc ( ) : Send -> T ) -> Result < T , ~Any : Send > {
243- /*!
244- * Execute a function in another task and return either the return value
245- * of the function or result::err.
246- *
247- * This is equivalent to task().try.
248- */
249-
250- let task = task ( ) ;
251- task. try ( f)
244+ TaskBuilder :: new ( ) . try ( f)
252245}
253246
254247
@@ -298,7 +291,7 @@ fn test_unnamed_task() {
298291
299292#[ test]
300293fn test_owned_named_task ( ) {
301- task ( ) . named ( "ada lovelace" . to_owned ( ) ) . spawn ( proc ( ) {
294+ TaskBuilder :: new ( ) . named ( "ada lovelace" . to_owned ( ) ) . spawn ( proc ( ) {
302295 with_task_name ( |name| {
303296 assert ! ( name. unwrap( ) == "ada lovelace" ) ;
304297 } )
@@ -307,7 +300,7 @@ fn test_owned_named_task() {
307300
308301#[ test]
309302fn test_static_named_task ( ) {
310- task ( ) . named ( "ada lovelace" ) . spawn ( proc ( ) {
303+ TaskBuilder :: new ( ) . named ( "ada lovelace" ) . spawn ( proc ( ) {
311304 with_task_name ( |name| {
312305 assert ! ( name. unwrap( ) == "ada lovelace" ) ;
313306 } )
@@ -316,7 +309,7 @@ fn test_static_named_task() {
316309
317310#[ test]
318311fn test_send_named_task ( ) {
319- task ( ) . named ( "ada lovelace" . into_maybe_owned ( ) ) . spawn ( proc ( ) {
312+ TaskBuilder :: new ( ) . named ( "ada lovelace" . into_maybe_owned ( ) ) . spawn ( proc ( ) {
320313 with_task_name ( |name| {
321314 assert ! ( name. unwrap( ) == "ada lovelace" ) ;
322315 } )
@@ -326,7 +319,7 @@ fn test_send_named_task() {
326319#[ test]
327320fn test_run_basic ( ) {
328321 let ( tx, rx) = channel ( ) ;
329- task ( ) . spawn ( proc ( ) {
322+ TaskBuilder :: new ( ) . spawn ( proc ( ) {
330323 tx. send ( ( ) ) ;
331324 } ) ;
332325 rx. recv ( ) ;
@@ -335,7 +328,7 @@ fn test_run_basic() {
335328#[ test]
336329fn test_with_wrapper ( ) {
337330 let ( tx, rx) = channel ( ) ;
338- task ( ) . with_wrapper ( proc ( body) {
331+ TaskBuilder :: new ( ) . with_wrapper ( proc ( body) {
339332 let result: proc ( ) : Send = proc ( ) {
340333 body ( ) ;
341334 tx. send ( ( ) ) ;
@@ -347,12 +340,12 @@ fn test_with_wrapper() {
347340
348341#[ test]
349342fn test_future_result ( ) {
350- let mut builder = task ( ) ;
343+ let mut builder = TaskBuilder :: new ( ) ;
351344 let result = builder. future_result ( ) ;
352345 builder. spawn ( proc ( ) { } ) ;
353346 assert ! ( result. recv( ) . is_ok( ) ) ;
354347
355- let mut builder = task ( ) ;
348+ let mut builder = TaskBuilder :: new ( ) ;
356349 let result = builder. future_result ( ) ;
357350 builder. spawn ( proc ( ) {
358351 fail ! ( ) ;
@@ -362,7 +355,7 @@ fn test_future_result() {
362355
363356#[ test] #[ should_fail]
364357fn test_back_to_the_future_result ( ) {
365- let mut builder = task ( ) ;
358+ let mut builder = TaskBuilder :: new ( ) ;
366359 builder. future_result ( ) ;
367360 builder. future_result ( ) ;
368361}
@@ -445,7 +438,7 @@ fn test_avoid_copying_the_body_spawn() {
445438#[ test]
446439fn test_avoid_copying_the_body_task_spawn ( ) {
447440 avoid_copying_the_body ( |f| {
448- let builder = task ( ) ;
441+ let builder = TaskBuilder :: new ( ) ;
449442 builder. spawn ( proc ( ) {
450443 f ( ) ;
451444 } ) ;
@@ -471,11 +464,11 @@ fn test_child_doesnt_ref_parent() {
471464 fn child_no ( x : uint ) -> proc ( ) : Send {
472465 return proc ( ) {
473466 if x < generations {
474- task ( ) . spawn ( child_no ( x+1 ) ) ;
467+ TaskBuilder :: new ( ) . spawn ( child_no ( x+1 ) ) ;
475468 }
476469 }
477470 }
478- task ( ) . spawn ( child_no ( 0 ) ) ;
471+ TaskBuilder :: new ( ) . spawn ( child_no ( 0 ) ) ;
479472}
480473
481474#[ test]
0 commit comments