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"
11
11
12
12
[dev-dependencies ]
13
13
tokio = " =0.2.0-alpha.1"
14
+ tokio-test = " =0.2.0-alpha.1"
14
15
futures-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()));
30
30
31
31
// ===== impl Sender =====
32
32
33
- impl < T : Unpin + ' static > Sender < T > {
33
+ impl < T : Unpin > Sender < T > {
34
34
pub fn send ( & mut self , value : T ) -> impl Future < Output = ( ) > {
35
35
Send { value : Some ( value) }
36
36
}
@@ -40,7 +40,7 @@ struct Send<T> {
40
40
value : Option < T > ,
41
41
}
42
42
43
- impl < T : Unpin + ' static > Future for Send < T > {
43
+ impl < T : Unpin > Future for Send < T > {
44
44
type Output = ( ) ;
45
45
46
46
fn poll ( mut self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < ( ) > {
Original file line number Diff line number Diff line change 2
2
3
3
use async_stream:: stream;
4
4
5
- use tokio:: prelude:: * ;
6
5
use futures_util:: pin_mut;
6
+ use tokio:: prelude:: * ;
7
+ use tokio:: sync:: mpsc;
8
+ use tokio_test:: assert_ok;
7
9
8
10
#[ tokio:: test]
9
11
async fn noop_stream ( ) {
@@ -81,3 +83,43 @@ async fn return_stream() {
81
83
assert_eq ! ( 2 , values[ 1 ] ) ;
82
84
assert_eq ! ( 3 , values[ 2 ] ) ;
83
85
}
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