Crates.io | tokio-bichannel |
lib.rs | tokio-bichannel |
version | 1.0.2 |
source | src |
created_at | 2024-07-28 03:09:47.68373 |
updated_at | 2024-07-28 16:24:37.513023 |
description | Bidirectional tokio::sync::mpsc channel |
homepage | |
repository | https://github.com/Altanis/tokio-bichannel |
max_upload_size | |
id | 1317714 |
size | 8,968 |
A wrapper around tokio::sync::mpsc
channels to provide an easy bidirectional stream API.
Add this to your Cargo.toml
file:
tokio-bichannel = "1"
#[tokio::test]
async fn main() {
let (mut chan1, mut chan2) = channel::<String, String>(10);
chan1.send("Hello from chan1".to_string()).await.unwrap();
chan2.send("Hello from chan2".to_string()).await.unwrap();
let msg1 = chan2.recv().await.unwrap();
let msg2 = chan1.recv().await.unwrap();
assert_eq!(msg1, "Hello from chan1");
assert_eq!(msg2, "Hello from chan2");
}