@@ -258,24 +258,22 @@ impl TaskBuilder {
258258 self . opts . indestructible = true ;
259259 }
260260
261- /**
262- * Get a future representing the exit status of the task.
263- *
264- * Taking the value of the future will block until the child task
265- * terminates. The future-receiving callback specified will be called
266- * *before* the task is spawned; as such, do not invoke .get() within the
267- * closure; rather, store it in an outer variable/list for later use.
268- *
269- * Note that the future returning by this function is only useful for
270- * obtaining the value of the next task to be spawning with the
271- * builder. If additional tasks are spawned with the same builder
272- * then a new result future must be obtained prior to spawning each
273- * task.
274- *
275- * # Failure
276- * Fails if a future_result was already set for this task.
277- */
278- pub fn future_result ( & mut self , blk : & fn ( v : Port < TaskResult > ) ) {
261+ /// Get a future representing the exit status of the task.
262+ ///
263+ /// Taking the value of the future will block until the child task
264+ /// terminates. The future result return value will be created *before* the task is
265+ /// spawned; as such, do not invoke .get() on it directly;
266+ /// rather, store it in an outer variable/list for later use.
267+ ///
268+ /// Note that the future returned by this function is only useful for
269+ /// obtaining the value of the next task to be spawning with the
270+ /// builder. If additional tasks are spawned with the same builder
271+ /// then a new result future must be obtained prior to spawning each
272+ /// task.
273+ ///
274+ /// # Failure
275+ /// Fails if a future_result was already set for this task.
276+ pub fn future_result ( & mut self ) -> Port < TaskResult > {
279277 // FIXME (#3725): Once linked failure and notification are
280278 // handled in the library, I can imagine implementing this by just
281279 // registering an arbitrary number of task::on_exit handlers and
@@ -288,10 +286,10 @@ impl TaskBuilder {
288286 // Construct the future and give it to the caller.
289287 let ( notify_pipe_po, notify_pipe_ch) = stream :: < TaskResult > ( ) ;
290288
291- blk ( notify_pipe_po) ;
292-
293289 // Reconfigure self to use a notify channel.
294290 self . opts . notify_chan = Some ( notify_pipe_ch) ;
291+
292+ notify_pipe_po
295293 }
296294
297295 /// Name the task-to-be. Currently the name is used for identification
@@ -398,15 +396,14 @@ impl TaskBuilder {
398396 */
399397 pub fn try < T : Send > ( & mut self , f : ~fn ( ) -> T ) -> Result < T , ( ) > {
400398 let ( po, ch) = stream :: < T > ( ) ;
401- let mut result = None ;
402399
403- self . future_result ( |r| { result = Some ( r ) ; } ) ;
400+ let result = self . future_result ( ) ;
404401
405402 do self. spawn {
406403 ch. send ( f ( ) ) ;
407404 }
408405
409- match result. unwrap ( ) . recv ( ) {
406+ match result. recv ( ) {
410407 Success => result:: Ok ( po. recv ( ) ) ,
411408 Failure => result:: Err ( ( ) )
412409 }
@@ -1024,27 +1021,25 @@ fn test_add_wrapper() {
10241021
10251022#[ test]
10261023fn test_future_result ( ) {
1027- let mut result = None ;
10281024 let mut builder = task ( ) ;
1029- builder . future_result ( |r| result = Some ( r ) ) ;
1025+ let result = builder . future_result ( ) ;
10301026 do builder. spawn { }
1031- assert_eq ! ( result. unwrap ( ) . recv( ) , Success ) ;
1027+ assert_eq ! ( result. recv( ) , Success ) ;
10321028
1033- result = None ;
10341029 let mut builder = task ( ) ;
1035- builder . future_result ( |r| result = Some ( r ) ) ;
1030+ let result = builder . future_result ( ) ;
10361031 builder. unlinked ( ) ;
10371032 do builder. spawn {
10381033 fail2 ! ( ) ;
10391034 }
1040- assert_eq ! ( result. unwrap ( ) . recv( ) , Failure ) ;
1035+ assert_eq ! ( result. recv( ) , Failure ) ;
10411036}
10421037
10431038#[ test] #[ should_fail]
10441039fn test_back_to_the_future_result ( ) {
10451040 let mut builder = task ( ) ;
1046- builder. future_result ( util :: ignore ) ;
1047- builder. future_result ( util :: ignore ) ;
1041+ builder. future_result ( ) ;
1042+ builder. future_result ( ) ;
10481043}
10491044
10501045#[ test]
0 commit comments