Struct lunatic_process::mailbox::MessageMailbox
source · [−]pub struct MessageMailbox { /* private fields */ }Expand description
The MessageMailbox is a data structure holding all messages of a process.
If a Signal of type Message is received it will be taken from the Signal queue and put into
this structure. The order of messages is preserved. This struct also implements the Future
trait and pop() operations can be awaited on if the queue is empty.
Safety
This should be cancellation safe and can be used inside tokio::select! statements:
https://docs.rs/tokio/1.10.0/tokio/macro.select.html#cancellation-safety
Implementations
sourceimpl MessageMailbox
impl MessageMailbox
sourcepub async fn pop(&self, tags: Option<&[i64]>) -> Message
pub async fn pop(&self, tags: Option<&[i64]>) -> Message
Return message in FIFO order from mailbox.
If function is called with a tags value different from None, it will only return the first
message matching any of the tags.
If no message exist, blocks until a message is received.
sourcepub async fn pop_skip_search(&self, tags: Option<&[i64]>) -> Message
pub async fn pop_skip_search(&self, tags: Option<&[i64]>) -> Message
Similar to pop, but will assume right away that no message with this tags exists.
Sometimes we know that the message we are waiting on can’t have a particular tags already in the queue, so we can save ourself a search through the queue. This is often the case in a request/response architecture where we sent the tags to the remote server but couldn’t have gotten it back yet.
Safety
It may not be clear right away why it’s safe to skip looking through the queue. If we are waiting on a reply, didn’t we already send the message and couldn’t it already have been received and pushed into our queue?
The way processes work is that they run a bit of code, stop, look for new signals/messages
before running more code. This stop can only happen if there is an .await point in the
code. Sending signals/messages is not an async task and we don’t need to .await on it.
When using this function we need to make sure that sending a specific tag and waiting on it
doesn’t contain any .await calls in-between. This implementation detail can be hidden
inside of atomic host function calls so that end users don’t need to worry about it.
Trait Implementations
sourceimpl Clone for MessageMailbox
impl Clone for MessageMailbox
sourcefn clone(&self) -> MessageMailboxⓘNotable traits for &MessageMailboximpl Future for &MessageMailbox type Output = Message;
fn clone(&self) -> MessageMailboxⓘNotable traits for &MessageMailboximpl Future for &MessageMailbox type Output = Message;
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Default for MessageMailbox
impl Default for MessageMailbox
sourcefn default() -> MessageMailboxⓘNotable traits for &MessageMailboximpl Future for &MessageMailbox type Output = Message;
fn default() -> MessageMailboxⓘNotable traits for &MessageMailboximpl Future for &MessageMailbox type Output = Message;
Returns the “default value” for a type. Read more
sourceimpl Future for &MessageMailbox
impl Future for &MessageMailbox
Auto Trait Implementations
impl RefUnwindSafe for MessageMailbox
impl Send for MessageMailbox
impl Sync for MessageMailbox
impl Unpin for MessageMailbox
impl UnwindSafe for MessageMailbox
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more