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

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.

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.

Pushes a message into the mailbox.

If the message is being .awaited on, this call will immediately notify the waker that it’s ready, otherwise it will push it at the end of the queue.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

The type of value produced on completion.

Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.