Struct workflow_rs::core::prelude::Multiplexer
source · pub struct Multiplexer<T>{
pub channels: Arc<Mutex<HashMap<Id, Arc<Sender<T>>>>>,
/* private fields */
}Expand description
A simple MPMC (one to many) channel Multiplexer that broadcasts to
multiple registered receivers. Multiplexer<T> itself can be
cloned and used to broadcast using Multiplexer::broadcast()
or Multiplexer::try_broadcast(). To create a receiving channel,
you can call MultiplexerChannel<T>::from() and supply the
desired Multiplexer instance, or simply call Multiplexer::channel()
to create a new MultiplexerChannel instance. The receiving channel
gets unregistered when MultiplexerChannel is dropped or the
underlying Receiver is closed.
Fields§
§channels: Arc<Mutex<HashMap<Id, Arc<Sender<T>>>>>Implementations§
source§impl<T> Multiplexer<T>
impl<T> Multiplexer<T>
sourcepub fn new() -> Multiplexer<T>
pub fn new() -> Multiplexer<T>
Create a new Multiplexer instance
sourcepub fn channel(&self) -> MultiplexerChannel<T>
pub fn channel(&self) -> MultiplexerChannel<T>
Create a new multiplexer receiving channel
sourcepub async fn broadcast(&self, event: T) -> Result<(), ChannelError<T>>
pub async fn broadcast(&self, event: T) -> Result<(), ChannelError<T>>
Async Multiplexer::broadcast function that calls Sender::send() on all registered MultiplexerChannel instances.
sourcepub fn try_broadcast(&self, event: T) -> Result<(), ChannelError<T>>
pub fn try_broadcast(&self, event: T) -> Result<(), ChannelError<T>>
A synchronous Multiplexer::try_broadcast function that calls Sender::try_send() on all registered MultiplexerChannel instances.
This function holds a mutex for the duration of the broadcast.
Trait Implementations§
source§impl<T> Clone for Multiplexer<T>
impl<T> Clone for Multiplexer<T>
source§fn clone(&self) -> Multiplexer<T>
fn clone(&self) -> Multiplexer<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<T> Default for Multiplexer<T>
impl<T> Default for Multiplexer<T>
source§fn default() -> Multiplexer<T>
fn default() -> Multiplexer<T>
source§impl<T> From<&Multiplexer<T>> for MultiplexerChannel<T>
impl<T> From<&Multiplexer<T>> for MultiplexerChannel<T>
Create a MultiplexerChannel from Multiplexer by reference.