Struct nri::mpmc::MultiSender
[-] [+]
[src]
pub struct MultiSender<T: Send> { clients: Arc<Mutex<Vec<Sender<T>>>>, }
Multi-producer, multi-consumer manager. Hands out channels and holds onto the sending ends, and has methods for sending to one or all of them.
Fields
clients | All open client channels |
Methods
impl<T: Send + Clone> MultiSender<T>
fn new() -> MultiSender<T>
Create a new empty MultiSender with no clients
fn receiver(&mut self) -> Receiver<T>
Creates a channel, keeps the sending end and returns the receiving end
The receiving ends are kept in order, so the index is predictable in case you want to call send_one()
fn send(&self, msg: T)
Send a message to all clients
Does not check for disconnected clients (changed from panicbit's version), because the indices need to be predictable so that send_one() is usable
fn send_one(&self, i: usize, msg: T) -> Result<(), SendError<T>>
Send a message to one client
Client identified by index (TODO some better way)
fn disconnect_all(&mut self)
Forget about all the clients