pub struct Mailbox { /* private fields */ }Expand description
MPSC mailbox for an actor.
Uses lock-free bounded queues internally.
Backpressure is coordinated via a semaphore; async wakeup via Notify.
Implementations§
Source§impl Mailbox
impl Mailbox
Sourcepub fn new(actor_id: ActorId, config: MailboxConfig) -> Self
pub fn new(actor_id: ActorId, config: MailboxConfig) -> Self
Create a new mailbox.
Sourcepub fn try_send(&self, message: Message) -> Result<(), (Message, Error)>
pub fn try_send(&self, message: Message) -> Result<(), (Message, Error)>
Try to send a message to the mailbox (non-blocking).
Sourcepub async fn send(&self, message: Message) -> Result<()>
pub async fn send(&self, message: Message) -> Result<()>
Send a message to the mailbox (async, waits if full).
Sourcepub async fn recv(&self) -> Message
pub async fn recv(&self) -> Message
Receive a message from the mailbox (async, waits if empty).
Uses tokio::sync::Notify for efficient wakeup instead of busy-polling.
The Notified future is created and enabled before the emptiness
check, so a notify_waiters racing with this call cannot be missed
(lost-wakeup).
Sourcepub fn is_backpressured(&self) -> bool
pub fn is_backpressured(&self) -> bool
Check if the mailbox is in backpressure state.
Sourcepub fn remaining_capacity(&self) -> usize
pub fn remaining_capacity(&self) -> usize
Get remaining capacity.
Auto Trait Implementations§
impl !Freeze for Mailbox
impl RefUnwindSafe for Mailbox
impl Send for Mailbox
impl Sync for Mailbox
impl Unpin for Mailbox
impl UnsafeUnpin for Mailbox
impl UnwindSafe for Mailbox
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more