pub struct Sender<M: Message> { /* private fields */ }Expand description
A message producer that deliver messages
to the Receiver
Implementations§
source§impl<M: Message> Sender<M>
impl<M: Message> Sender<M>
sourcepub fn as_receiver(&self) -> Receiver<M>
pub fn as_receiver(&self) -> Receiver<M>
create an instance of Sender from Receiver
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
get the capcity of the channel
it will remain the usize::MAX
when created, but can be updated
via set_capacity
sourcepub fn set_capacity(&self, cap: usize)
pub fn set_capacity(&self, cap: usize)
set the capcity of message queue
when the messages reach the capcity
it will transimit the queue to
state STATUSFULL where no more
messages will be received
sourcepub fn message_number(&self) -> usize
pub fn message_number(&self) -> usize
get the number of messages remain in the queue
struct Num(uisze);
impl Message for Num {}
struct CrossBus;
impl Actor for CrossBus {
...
}
let (addr, _) = CrossBus::start();
let sender = addr.sender();
sender.send(Num(1)).unwrap();
sender.send(Num(2)).unwrap();
sender.send(Num(3)).unwrap();
assert_eq!(sender.message_number(), 3)sourcepub fn send(&self, msg: M) -> Result<(), QueueError<M>>where
M: Send,
pub fn send(&self, msg: M) -> Result<(), QueueError<M>>where M: Send,
directly push a message into the queue
the message will be inserted the queue and notify the receiver to wake
let sender = addr.sender();
sender.send(Num(1));sourcepub fn downgrade(&self) -> WeakSender<M>
pub fn downgrade(&self) -> WeakSender<M>
downgrade to WeakSender which can later be upgraded
NOTE that the underlying data could be moved or consumed or otherwise