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"
1515futures = " 0.3.24"
1616futures-channel = " 0.3.24"
1717futures-util = " 0.3.24"
18+ kanal = " 0.1.0-pre1"
1819tokio = { version = " 1.21.2" , features = [" full" ] }
Original file line number Diff line number Diff line change @@ -14,4 +14,6 @@ fn main() {
1414 async_priority_channel_example ( ) ;
1515 futures_channel_mpsc_example ( ) ;
1616 futures_channel_oneshot_example ( ) ;
17+ kanal_example ( ) ;
18+ kanal_async_example ( ) ;
1719}
Original file line number Diff line number Diff line change @@ -223,3 +223,33 @@ pub fn async_priority_channel_example() {
223223 assert_eq ! ( r. recv( ) . await , Ok ( ( "Bar" , 2 ) ) ) ;
224224 } ) ;
225225}
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