Struct workflow_core::channel::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§impl<T> From<&Multiplexer<T>> for MultiplexerChannel<T>
impl<T> From<&Multiplexer<T>> for MultiplexerChannel<T>
Create a MultiplexerChannel
from Multiplexer
by reference.
source§fn from(multiplexer: &Multiplexer<T>) -> Self
fn from(multiplexer: &Multiplexer<T>) -> Self
Auto Trait Implementations§
impl<T> Freeze for Multiplexer<T>
impl<T> RefUnwindSafe for Multiplexer<T>where
T: RefUnwindSafe,
impl<T> Send for Multiplexer<T>
impl<T> Sync for Multiplexer<T>
impl<T> Unpin for Multiplexer<T>where
T: Unpin,
impl<T> UnwindSafe for Multiplexer<T>where
T: UnwindSafe,
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)