Don't fail in port.try_recv() the second time. Close #7800.

This commit is contained in:
Ben Blum 2013-08-21 18:43:50 -04:00
parent b81f5c547c
commit 598072afa4
2 changed files with 13 additions and 6 deletions

View File

@ -50,6 +50,12 @@ impl<T> Cell<T> {
this.value.take_unwrap()
}
/// Yields the value if the cell is full, or `None` if it is empty.
pub fn take_opt(&self) -> Option<T> {
let this = unsafe { transmute_mut(self) };
this.value.take()
}
/// Returns the value, failing if the cell is full.
pub fn put_back(&self, value: T) {
let this = unsafe { transmute_mut(self) };

View File

@ -499,13 +499,14 @@ impl<T> GenericPort<T> for Port<T> {
}
fn try_recv(&self) -> Option<T> {
let pone = self.next.take();
match pone.try_recv() {
Some(StreamPayload { val, next }) => {
self.next.put_back(next);
Some(val)
do self.next.take_opt().map_move_default(None) |pone| {
match pone.try_recv() {
Some(StreamPayload { val, next }) => {
self.next.put_back(next);
Some(val)
}
None => None
}
None => None
}
}
}