Add a selectable trait.
This commit is contained in:
@@ -318,10 +318,22 @@ fn select2<A: send, B: send>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn selecti<T: send>(endpoints: &[&recv_packet<T>]) -> uint {
|
trait selectable {
|
||||||
|
pure fn header() -> *packet_header;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn selecti<T: selectable>(endpoints: &[T]) -> uint {
|
||||||
wait_many(endpoints.map(|p| p.header()))
|
wait_many(endpoints.map(|p| p.header()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn select2i<A: selectable, B: selectable>(a: A, b: B) -> either<(), ()> {
|
||||||
|
alt wait_many([a.header(), b.header()]/_) {
|
||||||
|
0 { left(()) }
|
||||||
|
1 { right(()) }
|
||||||
|
_ { fail "wait returned unexpected index" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[doc = "Waits on a set of endpoints. Returns a message, its index,
|
#[doc = "Waits on a set of endpoints. Returns a message, its index,
|
||||||
and a list of the remaining endpoints."]
|
and a list of the remaining endpoints."]
|
||||||
fn select<T: send>(+endpoints: ~[recv_packet<T>])
|
fn select<T: send>(+endpoints: ~[recv_packet<T>])
|
||||||
@@ -552,7 +564,7 @@ class port_set<T: send> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl private_methods/&<T: send> for pipes::port<T> {
|
impl<T: send> of selectable for pipes::port<T> {
|
||||||
pure fn header() -> *pipes::packet_header unchecked {
|
pure fn header() -> *pipes::packet_header unchecked {
|
||||||
alt self.endp {
|
alt self.endp {
|
||||||
some(endp) {
|
some(endp) {
|
||||||
|
|||||||
Reference in New Issue
Block a user