File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -73,8 +73,17 @@ tag task_notification {
73
73
exit( task, task_result) ;
74
74
}
75
75
76
- fn join ( t : task ) -> task_result {
77
- join_id ( cast ( t) )
76
+ fn join ( task_port : ( task_id , comm:: port < task_notification > ) )
77
+ -> task_result {
78
+ let ( id, port) = task_port;
79
+ while true {
80
+ alt comm:: recv :: < task_notification > ( port) {
81
+ exit ( _id, res) {
82
+ if _id == id { ret res }
83
+ }
84
+ }
85
+ }
86
+ fail
78
87
}
79
88
80
89
fn join_id ( t : task_id ) -> task_result {
@@ -104,6 +113,12 @@ fn spawn_notify(thunk : -fn() -> (), notify : _chan<task_notification>)
104
113
spawn_inner ( thunk, some ( notify) )
105
114
}
106
115
116
+ fn spawn_joinable ( thunk : -fn ( ) ) -> ( task_id , comm:: port < task_notification > ) {
117
+ let p = comm:: port :: < task_notification > ( ) ;
118
+ let id = spawn_notify ( thunk, comm:: chan :: < task_notification > ( p) ) ;
119
+ ret ( id, p) ;
120
+ }
121
+
107
122
// FIXME: make this a fn~ once those are supported.
108
123
fn spawn_inner ( thunk : -fn ( ) -> ( ) ,
109
124
notify : option < _chan < task_notification > > )
Original file line number Diff line number Diff line change @@ -72,3 +72,11 @@ fn test_join_chan_fail() {
72
72
_ { fail "invalid task status received" }
73
73
}
74
74
}
75
+
76
+ #[ test]
77
+ fn test_join_convenient ( ) {
78
+ fn winner ( ) { }
79
+ let f = winner;
80
+ let handle = task:: spawn_joinable ( f) ;
81
+ assert ( task:: tr_success == task:: join ( handle) ) ;
82
+ }
You can’t perform that action at this time.
0 commit comments