Crates.io | channel-async |
lib.rs | channel-async |
version | 0.3.0-deprecated |
source | src |
created_at | 2019-08-14 18:00:19.682491 |
updated_at | 2019-11-15 17:36:36.522843 |
description | Async/Stream Extensions for crossbeam-channel |
homepage | |
repository | https://github.com/dbcfd/channel-async |
max_upload_size | |
id | 156825 |
size | 17,941 |
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.
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());
}
This project is licensed under the MIT license.
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.