Skip to content

Commit 020c5ca

Browse files
committed
---
yaml --- r: 22756 b: refs/heads/master c: 62d4f8f h: refs/heads/master v: v3
1 parent 411247d commit 020c5ca

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 531ea695f64e8d7105f904c515a6ff84fa32dc77
2+
refs/heads/master: 62d4f8fe825c907bd03c275f85aeeaf7b25c4336
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/pipes.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,3 +822,52 @@ impl chan<T: send> of channel<T> for shared_chan<T> {
822822
fn shared_chan<T:send>(+c: chan<T>) -> shared_chan<T> {
823823
arc::exclusive(c)
824824
}
825+
826+
trait select2<T: send, U: send> {
827+
fn try_select() -> either<option<T>, option<U>>;
828+
fn select() -> either<T, U>;
829+
}
830+
831+
impl<T: send, U: send, Left: selectable recv<T>, Right: selectable recv<U>>
832+
of select2<T, U> for (Left, Right) {
833+
834+
fn select() -> either<T, U> {
835+
alt self {
836+
(lp, rp) {
837+
alt select2i(lp, rp) {
838+
left(()) { left (lp.recv()) }
839+
right(()) { right(rp.recv()) }
840+
}
841+
}
842+
}
843+
}
844+
845+
fn try_select() -> either<option<T>, option<U>> {
846+
alt self {
847+
(lp, rp) {
848+
alt select2i(lp, rp) {
849+
left(()) { left (lp.try_recv()) }
850+
right(()) { right(rp.try_recv()) }
851+
}
852+
}
853+
}
854+
}
855+
}
856+
857+
#[cfg(test)]
858+
mod test {
859+
#[test]
860+
fn test_select2() {
861+
let (c1, p1) = pipes::stream();
862+
let (c2, p2) = pipes::stream();
863+
864+
c1.send("abc");
865+
866+
alt (p1, p2).select() {
867+
right(_) { fail }
868+
_ { }
869+
}
870+
871+
c2.send(123);
872+
}
873+
}

0 commit comments

Comments
 (0)