channel-async 0.3.0-alpha.2

Async/Stream Extensions for crossbeam-channel
Documentation

channel-async

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

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.1"

Next, add this to your crate:

use futures::{FutureExt, TryFutureExt};

let mut rt = tokio::runtime::Runtime::new().expect("Failed to create runtime");

let (tx, rx) = channel_async::unbounded(Duration::from_millis(100));

let send_fut = async move {
    for i in 1..100 {
        await!(tx.send(i))?;
    }
    Ok(())
};

rt.spawn(send_fut.map_err(|e| {
    error!("Failed to send: {:?}", e);
    ()
}).boxed().compat());

let recv_fut = rx
    .try_fold(vec![], |mut agg, v| {
        agg.push(v);
        futures::future::ready(Ok(agg))
    })
    .boxed()
    .compat();

let rcvd = rt.block_on(recv_fut);

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.