File tree Expand file tree Collapse file tree 3 files changed +46
-3
lines changed
Expand file tree Collapse file tree 3 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -11,4 +11,5 @@ proc-macro-hack = "0.5.8"
1111
1212[dev-dependencies ]
1313tokio = " =0.2.0-alpha.1"
14+ tokio-test = " =0.2.0-alpha.1"
1415futures-util-preview = " =0.3.0-alpha.17"
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ thread_local!(static STORE: Cell<*mut ()> = Cell::new(ptr::null_mut()));
3030
3131// ===== impl Sender =====
3232
33- impl < T : Unpin + ' static > Sender < T > {
33+ impl < T : Unpin > Sender < T > {
3434 pub fn send ( & mut self , value : T ) -> impl Future < Output = ( ) > {
3535 Send { value : Some ( value) }
3636 }
@@ -40,7 +40,7 @@ struct Send<T> {
4040 value : Option < T > ,
4141}
4242
43- impl < T : Unpin + ' static > Future for Send < T > {
43+ impl < T : Unpin > Future for Send < T > {
4444 type Output = ( ) ;
4545
4646 fn poll ( mut self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < ( ) > {
Original file line number Diff line number Diff line change 22
33use async_stream:: stream;
44
5- use tokio:: prelude:: * ;
65use futures_util:: pin_mut;
6+ use tokio:: prelude:: * ;
7+ use tokio:: sync:: mpsc;
8+ use tokio_test:: assert_ok;
79
810#[ tokio:: test]
911async fn noop_stream ( ) {
@@ -81,3 +83,43 @@ async fn return_stream() {
8183 assert_eq ! ( 2 , values[ 1 ] ) ;
8284 assert_eq ! ( 3 , values[ 2 ] ) ;
8385}
86+
87+ #[ tokio:: test]
88+ async fn consume_channel ( ) {
89+ let ( mut tx, mut rx) = mpsc:: channel ( 10 ) ;
90+
91+ let s = stream ! {
92+ while let Some ( v) = rx. recv( ) . await {
93+ yield v;
94+ }
95+ } ;
96+
97+ pin_mut ! ( s) ;
98+
99+ for i in 0 ..3 {
100+ assert_ok ! ( tx. send( i) . await ) ;
101+ assert_eq ! ( Some ( i) , s. next( ) . await ) ;
102+ }
103+
104+ drop ( tx) ;
105+ assert_eq ! ( None , s. next( ) . await ) ;
106+ }
107+
108+ #[ tokio:: test]
109+ async fn borrow_self ( ) {
110+ struct Data ( String ) ;
111+
112+ impl Data {
113+ fn stream < ' a > ( & ' a self ) -> impl Stream < Item = & str > + ' a {
114+ stream ! {
115+ yield & self . 0 [ ..] ;
116+ }
117+ }
118+ }
119+
120+ let data = Data ( "hello" . to_string ( ) ) ;
121+ let s = data. stream ( ) ;
122+ pin_mut ! ( s) ;
123+
124+ assert_eq ! ( Some ( "hello" ) , s. next( ) . await ) ;
125+ }
You can’t perform that action at this time.
0 commit comments