[−][src]Struct turbulence::message_channels::MessageChannels
Manages a set of channels through a packet multiplexer, where each channel is associated with exactly one message type.
Acts as a bridge between the sync and async worlds. Provides sync methods to send and receive
messages that do not block or error. The only error condition is if any of the backing tasks
end or if the backing packet channels are dropped, the MessageChannels
will permanently go
into a "disconnected" state.
Additionally still provides async versions of methods to send and receive messages that share the same simplified error handling, which may be useful during startup or shutdown.
Implementations
impl MessageChannels
[src]
pub fn is_connected(&self) -> bool
[src]
Returns whether this MessageChannels
has become disconnected because the backing network
task has errored.
Once it has become disconnected, a MessageChannels
is permanently in this errored state.
You can receive the error from the task by calling MessageChannels::recv_err
.
pub async fn recv_err(self) -> ChannelTaskError
[src]
Consume this MessageChannels
and receive the networking task shutdown error.
If this MessageChannels
is disconnected, returns the error that caused it to become
disconnected. If it is not disconnected, it will become disconnected by calling this and
return that error.
pub fn send<M: ChannelMessage>(&mut self, message: M) -> Option<M>
[src]
Send the given message on the channel associated with its message type.
In order to ensure delivery, flush
should be called for the same message type to
immediately send any buffered messages.
If the mpsc channel for this message type is full, will return the message that was sent back to the caller. If the message was successfully put onto the outgoing mpsc channel, will return None.
Panics
Panics if this message type was not registered with the MessageChannelsBuilder
used to
build this MessageChannels
instance.
pub fn try_send<M: ChannelMessage>(
&mut self,
message: M
) -> Result<Option<M>, MessageTypeUnregistered>
[src]
&mut self,
message: M
) -> Result<Option<M>, MessageTypeUnregistered>
Like MessageChannels::send
but errors instead of panicking when the message type is
unregistered.
pub async fn async_send<M: ChannelMessage, '_>(
&'_ mut self,
message: M
) -> Result<(), MessageChannelsDisconnected>
[src]
&'_ mut self,
message: M
) -> Result<(), MessageChannelsDisconnected>
Any async version of MessageChannels::send
, sends the given message on the channel
associated with its message type but waits if the channel is full. Like
MessageChannels::send
, MessageChannels::flush
must still be called afterwards in order
to ensure delivery.
Panics
Panics if this message type is not registered.
pub async fn try_async_send<M: ChannelMessage, '_>(
&'_ mut self,
message: M
) -> Result<(), TryAsyncMessageError>
[src]
&'_ mut self,
message: M
) -> Result<(), TryAsyncMessageError>
Like MessageChannels::async_send
but errors instead of panicking when the message type is
unregistered.
pub fn flush<M: ChannelMessage>(&mut self)
[src]
Immediately send any buffered messages for this message type. Messages may not be delivered
unless flush
is called after any send
calls.
Panics
Panics if this message type was not registered with the MessageChannelsBuilder
used to
build this MessageChannels
instance.
pub fn try_flush<M: ChannelMessage>(
&mut self
) -> Result<(), MessageTypeUnregistered>
[src]
&mut self
) -> Result<(), MessageTypeUnregistered>
Like MessageChannels::flush
but errors instead of panicking when the message type is
unregistered.
pub fn recv<M: ChannelMessage>(&mut self) -> Option<M>
[src]
Receive an incoming message on the channel associated with this mesage type, if one is available.
Panics
Panics if this message type was not registered with the MessageChannelsBuilder
used to
build this MessageChannels
instance.
pub fn try_recv<M: ChannelMessage>(
&mut self
) -> Result<Option<M>, MessageTypeUnregistered>
[src]
&mut self
) -> Result<Option<M>, MessageTypeUnregistered>
Like MessageChannels::recv
but errors instead of panicking when the message type is
unregistered.
pub async fn async_recv<M: ChannelMessage, '_>(
&'_ mut self
) -> Result<M, MessageChannelsDisconnected>
[src]
&'_ mut self
) -> Result<M, MessageChannelsDisconnected>
Any async version of MessageChannels::receive
, receives an incoming message on the channel
associated with its message type but waits if there is no message available.
Panics
Panics if this message type is not registered.
pub async fn try_async_recv<M: ChannelMessage, '_>(
&'_ mut self
) -> Result<M, TryAsyncMessageError>
[src]
&'_ mut self
) -> Result<M, TryAsyncMessageError>
Like MessageChannels::async_recv
but errors instead of panicking when the message type is
unregistered.
pub fn statistics<M: ChannelMessage>(&self) -> &ChannelStatistics
[src]
pub fn try_statistics<M: ChannelMessage>(
&self
) -> Result<&ChannelStatistics, MessageTypeUnregistered>
[src]
&self
) -> Result<&ChannelStatistics, MessageTypeUnregistered>
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for MessageChannels
impl Send for MessageChannels
impl Sync for MessageChannels
impl Unpin for MessageChannels
impl !UnwindSafe for MessageChannels
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,