about summary refs log tree commit diff
path: root/src/lib
diff options
context:
space:
mode:
authorEric Holk <eholk@mozilla.com>2011-08-17 15:07:19 -0700
committerEric Holk <eholk@mozilla.com>2011-08-17 15:07:19 -0700
commit9e020b8b8f0f40ae905f44320009d6d067a60510 (patch)
tree68580a92a72a7dfa0b0c6effcbc7146d30cd3a2d /src/lib
parentae89ea223de2fe5e9c9a5cdd2fa85a93828a7daa (diff)
Convenience methods for spawning and joining tasks.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/task.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/lib/task.rs b/src/lib/task.rs
index d3f26ce769b..4ad160df603 100644
--- a/src/lib/task.rs
+++ b/src/lib/task.rs
@@ -73,8 +73,17 @@ tag task_notification {
     exit(task, task_result);
 }
 
-fn join(t: task) -> task_result {
-    join_id(cast(t))
+fn join(task_port : (task_id, comm::port<task_notification>))
+    -> task_result {
+    let (id, port) = task_port;
+    while true {
+        alt comm::recv::<task_notification>(port) {
+          exit(_id, res) {
+            if _id == id { ret res }
+          }
+        }
+    }
+    fail
 }
 
 fn join_id(t : task_id) -> task_result {
@@ -104,6 +113,12 @@ fn spawn_notify(thunk : -fn() -> (), notify : _chan<task_notification>)
     spawn_inner(thunk, some(notify))
 }
 
+fn spawn_joinable(thunk : -fn()) -> (task_id, comm::port<task_notification>) {
+    let p = comm::port::<task_notification>();
+    let id = spawn_notify(thunk, comm::chan::<task_notification>(p));
+    ret (id, p);
+}
+
 // FIXME: make this a fn~ once those are supported.
 fn spawn_inner(thunk : -fn() -> (),
                notify : option<_chan<task_notification>>)