• 0 Posts
  • 688 Comments
Joined 10 months ago
cake
Cake day: July 19th, 2024

help-circle












  • 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.