@@ -3,15 +3,12 @@ use crate::future::{Either, FutureExt};
3
3
use core:: pin:: Pin ;
4
4
use futures_core:: future:: { FusedFuture , Future } ;
5
5
use futures_core:: task:: { Context , Poll } ;
6
- use rand:: rngs:: SmallRng ;
7
- use rand:: Rng ;
8
6
9
7
/// Future for the [`select()`] function.
10
8
#[ must_use = "futures do nothing unless you `.await` or poll them" ]
11
9
#[ derive( Debug ) ]
12
10
pub struct Select < A , B > {
13
11
inner : Option < ( A , B ) > ,
14
- rng : SmallRng ,
15
12
}
16
13
17
14
impl < A : Unpin , B : Unpin > Unpin for Select < A , B > { }
94
91
{
95
92
assert_future :: < Either < ( A :: Output , B ) , ( B :: Output , A ) > , _ > ( Select {
96
93
inner : Some ( ( future1, future2) ) ,
97
- rng : crate :: gen_rng ( ) ,
98
94
} )
99
95
}
100
96
@@ -116,7 +112,6 @@ where
116
112
}
117
113
}
118
114
119
- let a_polls_first = self . rng . gen :: < bool > ( ) ;
120
115
let ( a, b) = self . inner . as_mut ( ) . expect ( "cannot poll Select twice" ) ;
121
116
122
117
macro_rules! poll_wrap {
@@ -127,13 +122,20 @@ where
127
122
} ;
128
123
}
129
124
130
- if a_polls_first {
125
+ #[ cfg( feature = "std" ) ]
126
+ if crate :: gen_index ( 2 ) == 0 {
131
127
poll_wrap ! ( a, unwrap_option( self . inner. take( ) ) . 1 , Either :: Left ) ;
132
128
poll_wrap ! ( b, unwrap_option( self . inner. take( ) ) . 0 , Either :: Right ) ;
133
129
} else {
134
130
poll_wrap ! ( b, unwrap_option( self . inner. take( ) ) . 0 , Either :: Right ) ;
135
131
poll_wrap ! ( a, unwrap_option( self . inner. take( ) ) . 1 , Either :: Left ) ;
136
132
}
133
+
134
+ #[ cfg( not( feature = "std" ) ) ]
135
+ {
136
+ poll_wrap ! ( a, unwrap_option( self . inner. take( ) ) . 1 , Either :: Left ) ;
137
+ poll_wrap ! ( b, unwrap_option( self . inner. take( ) ) . 0 , Either :: Right ) ;
138
+ }
137
139
Poll :: Pending
138
140
}
139
141
}
0 commit comments