Skip to content

Commit

Permalink
std: Don't fail the task when a Future is dropped
Browse files Browse the repository at this point in the history
It's a benign failure that no one needs to know about.

Closes rust-lang#14892
  • Loading branch information
alexcrichton committed Jun 16, 2014
1 parent 0b32d42 commit 1b0e35b
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/libstd/sync/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -144,6 +145,7 @@ mod test {
use prelude::*;
use sync::Future;
use task;
use comm::{channel, Sender};

#[test]
fn test_from_value() {
Expand Down Expand Up @@ -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());
}
}

1 comment on commit 1b0e35b

@lilyball
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Please sign in to comment.