File tree Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 531ea695f64e8d7105f904c515a6ff84fa32dc77
2
+ refs/heads/master: 62d4f8fe825c907bd03c275f85aeeaf7b25c4336
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
5
5
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
Original file line number Diff line number Diff line change @@ -822,3 +822,52 @@ impl chan<T: send> of channel<T> for shared_chan<T> {
822
822
fn shared_chan < T : send > ( +c : chan < T > ) -> shared_chan < T > {
823
823
arc:: exclusive ( c)
824
824
}
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
+ }
You can’t perform that action at this time.
0 commit comments