channelmap

Crates.iochannelmap
lib.rschannelmap
version0.4.0
created_at2025-04-28 21:57:20.275221+00
updated_at2025-05-01 01:21:24.026501+00
descriptionA DashMap wrapper over Tokio channels
homepage
repositoryhttps://github.com/some100/channelmap
max_upload_size
id1652718
size24,070
someone (some100)

documentation

README

ChannelMap

A DashMap wrapper over asynchronous flume channels. Provides a convenient way to send messages over named channels.

Example

use channelmap::ChannelMap;
use tokio::task::JoinSet;

#[tokio::main] // (or whatever executor you're using)
async fn main() {
    let channels = ChannelMap::new();
    let mut set = JoinSet::new();

    for i in 0..10 {
        let rx = channels.add(&i.to_string()).unwrap();
        set.spawn(async move {
            let msg = rx.recv_async().await.unwrap();
            assert_eq!(msg, "bar");
            println!("Channel {i} got message {msg}");
        });
    }

    for tx in channels.iter() {
        tx.send("bar").unwrap();
    }
    
    set.join_all().await;
}

License

Licensed under MIT.

Commit count: 6

cargo fmt