1
Fork 0

fix recv_ready for Port to take &self and not need to return a tuple. Close #8192.

This commit is contained in:
Ben Blum 2013-08-05 19:58:10 -04:00 committed by Corey Richardson
parent 898226f39a
commit 8ebdb37fd2
2 changed files with 26 additions and 7 deletions

View file

@ -508,7 +508,11 @@ impl<T> Peekable<T> for Port<T> {
}
}
impl<T> Select for Port<T> {
// XXX: Kind of gross. A Port<T> should be selectable so you can make an array
// of them, but a &Port<T> should also be selectable so you can select2 on it
// alongside a PortOne<U> without passing the port by value in recv_ready.
impl<'self, T> Select for &'self Port<T> {
#[inline]
fn optimistic_check(&mut self) -> bool {
do self.next.with_mut_ref |pone| { pone.optimistic_check() }
@ -526,12 +530,29 @@ impl<T> Select for Port<T> {
}
}
impl<T> SelectPort<(T, Port<T>)> for Port<T> {
fn recv_ready(self) -> Option<(T, Port<T>)> {
impl<T> Select for Port<T> {
#[inline]
fn optimistic_check(&mut self) -> bool {
(&*self).optimistic_check()
}
#[inline]
fn block_on(&mut self, sched: &mut Scheduler, task: BlockedTask) -> bool {
(&*self).block_on(sched, task)
}
#[inline]
fn unblock_from(&mut self) -> bool {
(&*self).unblock_from()
}
}
impl<'self, T> SelectPort<T> for &'self Port<T> {
fn recv_ready(self) -> Option<T> {
match self.next.take().recv_ready() {
Some(StreamPayload { val, next }) => {
self.next.put_back(next);
Some((val, self))
Some(val)
}
None => None
}

View file

@ -199,9 +199,7 @@ mod test {
// get it back out
util::swap(port.get_mut_ref(), &mut ports[index]);
// NB. Not recv(), because optimistic_check randomly fails.
let (data, new_port) = port.take_unwrap().recv_ready().unwrap();
assert!(data == 31337);
port = Some(new_port);
assert!(port.get_ref().recv_ready().unwrap() == 31337);
}
}
}