about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-06-26 19:46:25 +0000
committerbors <bors@rust-lang.org>2014-06-26 19:46:25 +0000
commit4c33a14cc546ddacd5398cebf57aa5ac574cfea7 (patch)
tree21d47ac21cd9785976f1551a459df6e033f37712 /src/libstd
parentb20f968ed2a4808f98ffce52ce95398009565ece (diff)
parent7d756e44a96c1e28f63cab1ea328d01984ac07d2 (diff)
downloadrust-4c33a14cc546ddacd5398cebf57aa5ac574cfea7.tar.gz
rust-4c33a14cc546ddacd5398cebf57aa5ac574cfea7.zip
auto merge of #14886 : alexcrichton/rust/rt-improvements, r=brson
Most of the comments are available on the Task structure itself, but this commit
is aimed at making FFI-style usage of Rust tasks a little nicer.

Primarily, this commit enables re-use of tasks across multiple invocations. The
method `run` will no longer unconditionally destroy the task itself. Rather, the
task will be internally re-usable if the closure specified did not fail. Once a
task has failed once it is considered poisoned and it can never be used again.

Along the way I tried to document shortcomings of the current method of tearing
down a task, opening a few issues as well. For now none of the behavior is a
showstopper, but it's useful to acknowledge it. Also along the way I attempted
to remove as much `unsafe` code as possible, opting for safer abstractions.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/task.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/libstd/task.rs b/src/libstd/task.rs
index e2d04a30a54..dad241002f8 100644
--- a/src/libstd/task.rs
+++ b/src/libstd/task.rs
@@ -295,8 +295,8 @@ impl<S: Spawner> TaskBuilder<S> {
         let (tx_done, rx_done) = channel(); // signal that task has exited
         let (tx_retv, rx_retv) = channel(); // return value from task
 
-        let on_exit = proc(res) { tx_done.send(res) };
-        self.spawn_internal(proc() { tx_retv.send(f()) },
+        let on_exit = proc(res) { let _ = tx_done.send_opt(res); };
+        self.spawn_internal(proc() { let _ = tx_retv.send_opt(f()); },
                             Some(on_exit));
 
         Future::from_fn(proc() {
@@ -641,3 +641,14 @@ mod test {
     // NOTE: the corresponding test for stderr is in run-pass/task-stderr, due
     // to the test harness apparently interfering with stderr configuration.
 }
+
+#[test]
+fn task_abort_no_kill_runtime() {
+    use std::io::timer;
+    use mem;
+
+    let mut tb = TaskBuilder::new();
+    let rx = tb.try_future(proc() {});
+    mem::drop(rx);
+    timer::sleep(1000);
+}