diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-06-16 13:24:31 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-06-16 18:16:14 -0700 |
| commit | 01dc27a219435714ec38d0a2ddd1594d96e4da72 (patch) | |
| tree | eaacc99d8009dfb522a028b53a52c2478307df5e /src/libstd/sync | |
| parent | 0439162d597d4abfebf93096e71ff45242efe6f0 (diff) | |
| download | rust-01dc27a219435714ec38d0a2ddd1594d96e4da72.tar.gz rust-01dc27a219435714ec38d0a2ddd1594d96e4da72.zip | |
std: Don't fail the task when a Future is dropped
It's a benign failure that no one needs to know about. Closes #14892
Diffstat (limited to 'src/libstd/sync')
| -rw-r--r-- | src/libstd/sync/future.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index bc748324fcd..ccc67e3f8b0 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -132,7 +132,8 @@ impl<A:Send> Future<A> { let (tx, rx) = channel(); spawn(proc() { - tx.send(blk()); + // Don't fail if the other end has hung up + let _ = tx.send_opt(blk()); }); Future::from_receiver(rx) @@ -144,6 +145,7 @@ mod test { use prelude::*; use sync::Future; use task; + use comm::{channel, Sender}; #[test] fn test_from_value() { @@ -206,4 +208,28 @@ mod test { assert_eq!(actual, expected); }); } + + #[test] + fn test_dropped_future_doesnt_fail() { + struct Bomb(Sender<bool>); + + local_data_key!(LOCAL: Bomb) + + impl Drop for Bomb { + fn drop(&mut self) { + let Bomb(ref tx) = *self; + tx.send(task::failing()); + } + } + + // Spawn a future, but drop it immediately. When we receive the result + // later on, we should never view the task as having failed. + let (tx, rx) = channel(); + drop(Future::spawn(proc() { + LOCAL.replace(Some(Bomb(tx))); + })); + + // Make sure the future didn't fail the task. + assert!(!rx.recv()); + } } |
