Skip to content

Commit b19d7fa

Browse files
author
Eric Holk
committed
---
yaml --- r: 4775 b: refs/heads/master c: 9e020b8 h: refs/heads/master i: 4773: a3472a9 4771: e72bbed 4767: 1c784cc v: v3
1 parent d43548b commit b19d7fa

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: ae89ea223de2fe5e9c9a5cdd2fa85a93828a7daa
2+
refs/heads/master: 9e020b8b8f0f40ae905f44320009d6d067a60510

trunk/src/lib/task.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,17 @@ tag task_notification {
7373
exit(task, task_result);
7474
}
7575

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
7887
}
7988

8089
fn join_id(t : task_id) -> task_result {
@@ -104,6 +113,12 @@ fn spawn_notify(thunk : -fn() -> (), notify : _chan<task_notification>)
104113
spawn_inner(thunk, some(notify))
105114
}
106115

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+
107122
// FIXME: make this a fn~ once those are supported.
108123
fn spawn_inner(thunk : -fn() -> (),
109124
notify : option<_chan<task_notification>>)

trunk/src/test/stdtest/task.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,11 @@ fn test_join_chan_fail() {
7272
_ { fail "invalid task status received" }
7373
}
7474
}
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+
}

0 commit comments

Comments
 (0)