@@ -258,24 +258,22 @@ impl TaskBuilder {
258
258
self . opts . indestructible = true ;
259
259
}
260
260
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 > {
279
277
// FIXME (#3725): Once linked failure and notification are
280
278
// handled in the library, I can imagine implementing this by just
281
279
// registering an arbitrary number of task::on_exit handlers and
@@ -288,10 +286,10 @@ impl TaskBuilder {
288
286
// Construct the future and give it to the caller.
289
287
let ( notify_pipe_po, notify_pipe_ch) = stream :: < TaskResult > ( ) ;
290
288
291
- blk ( notify_pipe_po) ;
292
-
293
289
// Reconfigure self to use a notify channel.
294
290
self . opts . notify_chan = Some ( notify_pipe_ch) ;
291
+
292
+ notify_pipe_po
295
293
}
296
294
297
295
/// Name the task-to-be. Currently the name is used for identification
@@ -398,15 +396,14 @@ impl TaskBuilder {
398
396
*/
399
397
pub fn try < T : Send > ( & mut self , f : ~fn ( ) -> T ) -> Result < T , ( ) > {
400
398
let ( po, ch) = stream :: < T > ( ) ;
401
- let mut result = None ;
402
399
403
- self . future_result ( |r| { result = Some ( r ) ; } ) ;
400
+ let result = self . future_result ( ) ;
404
401
405
402
do self. spawn {
406
403
ch. send ( f ( ) ) ;
407
404
}
408
405
409
- match result. unwrap ( ) . recv ( ) {
406
+ match result. recv ( ) {
410
407
Success => result:: Ok ( po. recv ( ) ) ,
411
408
Failure => result:: Err ( ( ) )
412
409
}
@@ -1024,27 +1021,25 @@ fn test_add_wrapper() {
1024
1021
1025
1022
#[ test]
1026
1023
fn test_future_result ( ) {
1027
- let mut result = None ;
1028
1024
let mut builder = task ( ) ;
1029
- builder . future_result ( |r| result = Some ( r ) ) ;
1025
+ let result = builder . future_result ( ) ;
1030
1026
do builder. spawn { }
1031
- assert_eq ! ( result. unwrap ( ) . recv( ) , Success ) ;
1027
+ assert_eq ! ( result. recv( ) , Success ) ;
1032
1028
1033
- result = None ;
1034
1029
let mut builder = task ( ) ;
1035
- builder . future_result ( |r| result = Some ( r ) ) ;
1030
+ let result = builder . future_result ( ) ;
1036
1031
builder. unlinked ( ) ;
1037
1032
do builder. spawn {
1038
1033
fail2 ! ( ) ;
1039
1034
}
1040
- assert_eq ! ( result. unwrap ( ) . recv( ) , Failure ) ;
1035
+ assert_eq ! ( result. recv( ) , Failure ) ;
1041
1036
}
1042
1037
1043
1038
#[ test] #[ should_fail]
1044
1039
fn test_back_to_the_future_result ( ) {
1045
1040
let mut builder = task ( ) ;
1046
- builder. future_result ( util :: ignore ) ;
1047
- builder. future_result ( util :: ignore ) ;
1041
+ builder. future_result ( ) ;
1042
+ builder. future_result ( ) ;
1048
1043
}
1049
1044
1050
1045
#[ test]
0 commit comments