Skip to content

Commit 436d263

Browse files
committed
Add a selectable trait.
1 parent 0487663 commit 436d263

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/libcore/pipes.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,22 @@ fn select2<A: send, B: send>(
318318
}
319319
}
320320

321-
fn selecti<T: send>(endpoints: &[&recv_packet<T>]) -> uint {
321+
trait selectable {
322+
pure fn header() -> *packet_header;
323+
}
324+
325+
fn selecti<T: selectable>(endpoints: &[T]) -> uint {
322326
wait_many(endpoints.map(|p| p.header()))
323327
}
324328

329+
fn select2i<A: selectable, B: selectable>(a: A, b: B) -> either<(), ()> {
330+
alt wait_many([a.header(), b.header()]/_) {
331+
0 { left(()) }
332+
1 { right(()) }
333+
_ { fail "wait returned unexpected index" }
334+
}
335+
}
336+
325337
#[doc = "Waits on a set of endpoints. Returns a message, its index,
326338
and a list of the remaining endpoints."]
327339
fn select<T: send>(+endpoints: ~[recv_packet<T>])
@@ -552,7 +564,7 @@ class port_set<T: send> {
552564
}
553565
}
554566

555-
impl private_methods/&<T: send> for pipes::port<T> {
567+
impl<T: send> of selectable for pipes::port<T> {
556568
pure fn header() -> *pipes::packet_header unchecked {
557569
alt self.endp {
558570
some(endp) {

0 commit comments

Comments
 (0)