this post was submitted on 11 May 2025
9 points (100.0% liked)
Rust
7056 readers
19 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
You don't need to arc-mutex an mpsc. On the sender side, clone the sender as many times as you need and pass it by value (each sender owns a clone). On the receiver side you must have only one (mpsc is multiple producer single consumer) which is owned by the receiver.
If you need multiple producers and multiple consumers I recommend this crate: https://crates.io/crates/async-channel
The same pattern applies. No arc, no mutex, just clone the sender and receiver handles for each producer and consumer respectively.
Don't worry about the cloning, channels are specifically designed to be used this way.