File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -15,4 +15,5 @@ flume = "0.10.14"
15
15
futures = " 0.3.24"
16
16
futures-channel = " 0.3.24"
17
17
futures-util = " 0.3.24"
18
+ kanal = " 0.1.0-pre1"
18
19
tokio = { version = " 1.21.2" , features = [" full" ] }
Original file line number Diff line number Diff line change @@ -14,4 +14,6 @@ fn main() {
14
14
async_priority_channel_example ( ) ;
15
15
futures_channel_mpsc_example ( ) ;
16
16
futures_channel_oneshot_example ( ) ;
17
+ kanal_example ( ) ;
18
+ kanal_async_example ( ) ;
17
19
}
Original file line number Diff line number Diff line change @@ -223,3 +223,33 @@ pub fn async_priority_channel_example() {
223
223
assert_eq ! ( r. recv( ) . await , Ok ( ( "Bar" , 2 ) ) ) ;
224
224
} ) ;
225
225
}
226
+
227
+ pub fn kanal_example ( ) {
228
+ let ( tx, rx) = kanal:: unbounded ( ) ;
229
+
230
+ thread:: spawn ( move || {
231
+ ( 0 ..10 ) . for_each ( |i| {
232
+ tx. send ( i) . unwrap ( ) ;
233
+ } ) ;
234
+
235
+ drop ( tx)
236
+ } ) ;
237
+
238
+ let received: u32 = rx. sum ( ) ;
239
+
240
+ println ! ( "received sum: {}" , received) ;
241
+ }
242
+
243
+ pub fn kanal_async_example ( ) {
244
+ let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
245
+
246
+ let ( tx, rx) = kanal:: unbounded_async ( ) ;
247
+
248
+ rt. block_on ( async move {
249
+ tokio:: spawn ( async move {
250
+ tx. send ( 5 ) . await . unwrap ( ) ;
251
+ } ) ;
252
+
253
+ println ! ( "rx: {}" , rx. recv( ) . await . unwrap( ) ) ;
254
+ } ) ;
255
+ }
You can’t perform that action at this time.
0 commit comments