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§
Source§impl 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§
Source§impl Clone for MessageMailbox
impl Clone for MessageMailbox
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Default for MessageMailbox
impl Default for MessageMailbox
Source§impl Future for &MessageMailbox
impl Future for &MessageMailbox
Auto Trait Implementations§
impl Freeze for MessageMailbox
impl RefUnwindSafe for MessageMailbox
impl Send for MessageMailbox
impl Sync for MessageMailbox
impl Unpin for MessageMailbox
impl UnwindSafe for MessageMailbox
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self
file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self
file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more