Module comm::mpsc [−][src]
Multiple-producer, single-consumer (MPSC) channels.
MPSC channels can be dynamically allocated from a Switchboard
:
use comm::Switchboard; use futures::sink::SinkExt; use futures::stream::StreamExt; use tokio::net::UnixStream; let switchboard = Switchboard::local()?; let (tx, mut rx) = switchboard.mpsc(); tokio::spawn(async move { // Do work. let answer = 42; tx.connect().await?.send(answer).await?; Ok::<_, comm::Error>(()) }); assert_eq!(rx.next().await.transpose()?, Some(42));
Unconnected senders are quite flexible. They implement
Serialize
and Deserialize
so
that they can be sent over the network to other processes, or Clone
d and
shared with other threads in the same process.
Receivers and connected senders are less flexible, but still implement
Send
and so can be freely sent between threads.
Structs
Receiver | The receiving end of an MPSC channel. |
Sender | The transmission end of an MPSC channel. |