Skip to content

Commit

Permalink
Cancel on_empty on drop of FutureSender
Browse files Browse the repository at this point in the history
Fixes an assertion that otherwise gets tripped.

Closes rust-lang#184
  • Loading branch information
alexcrichton committed Oct 3, 2016
1 parent 111bfb2 commit 59de7fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/stream/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,13 @@ impl<T, E> Future for FutureSender<T, E> {
}
}
}

impl<T, E> Drop for FutureSender<T, E> {
fn drop(&mut self) {
if let Some(token) = self.on_empty_token.take() {
if let Some(sender) = self.sender.take() {
sender.inner.slot.cancel(token);
}
}
}
}
6 changes: 3 additions & 3 deletions tests/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ impl task::Unpark for Unpark {

#[test]
fn poll_future_then_drop() {
let (tx, _) = channel::<u32, u32>();
let (tx, _rx) = channel::<u32, u32>();

let tx = tx.send(Ok(1));
let mut t = task::spawn(tx);

// First poll succeeds
let tx = match t.poll_future(Arc::new(Unpark)) {
Ok(Async::Ready(tx)) => tx,
_ => unreachable!(),
_ => panic!(),
};

// Send another value
Expand All @@ -75,7 +75,7 @@ fn poll_future_then_drop() {
// Second poll doesn't
match t.poll_future(Arc::new(Unpark)) {
Ok(Async::NotReady) => {},
_ => unreachable!(),
_ => panic!(),
};

drop(t);
Expand Down

0 comments on commit 59de7fe

Please sign in to comment.