9 releases

0.3.0-deprecated Nov 15, 2019
0.3.0-alpha.8 Aug 30, 2019

#15 in #crossbeam

28 downloads per month

MIT license

11KB
194 lines

channel-async

build status crates.io version docs.rs docs MIT licensed

  • This crate is no longer maintained *

Due to interactions between crossbeam and tokio, it is recommended that you use the channels in async-std

Async/stream extensions to crossbeam-channel on top of Futures 0.3 Stream. It is primarily intended for usage with Tokio.

Documentation

Usage

First, add this to your Cargo.toml:

[dependencies]
channel-async = "0.3.0-alpha.8"

Next, add this to your crate:

use futures::{FutureExt, TryFutureExt};

#[tokio::main]
async fn run_channels() {
    let (tx, rx) = channel_async::unbounded(Duration::from_millis(100));

    let send_fut = async move {
        for i in 1..100 {
            tx.send(i).await.expect("Failed to send");
        }
    };
    
    tokio::spawn(send_fut);

    let recv_fut = async move {
      let rcvd: Vec<_> = rx.collect().await;
      rcvd
    };
    
    let rcvd = recv_fut.await;
    
    println!("Received {} messages", rcvd.len());
}

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in tls-async by you, shall be licensed as MIT, without any additional terms or conditions.

Dependencies

~6MB
~107K SLoC