Don't fail in port.try_recv() the second time. Close #7800.
This commit is contained in:
parent
b81f5c547c
commit
598072afa4
@ -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) };
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user