pub struct SerializedMulticast<'or, T, E, R = ()>(/* private fields */);Expand description
A shared, serialized delivery of events to many observers, guarding the host’s state with it.
R is whatever the host owns besides the observers: the current value of a behavior subject,
the buffer of a replay subject, () when it owns nothing.
Implementations§
Source§impl<'or, T, E, R> SerializedMulticast<'or, T, E, R>
impl<'or, T, E, R> SerializedMulticast<'or, T, E, R>
Source§impl<'or, T, E, R> SerializedMulticast<'or, T, E, R>
impl<'or, T, E, R> SerializedMulticast<'or, T, E, R>
Sourcepub fn terminated(&self) -> Option<Termination<E>>
pub fn terminated(&self) -> Option<Termination<E>>
The termination, once one has been queued.
The resources are gone once the delivery stopped, which only an observer’s panic does: the multicast is then dead, and reports no termination.
Sourcepub fn read<Out>(
&self,
read: impl FnOnce(&R, Option<&Termination<E>>) -> Out,
) -> Result<Out, DeliveryStopped>
pub fn read<Out>( &self, read: impl FnOnce(&R, Option<&Termination<E>>) -> Out, ) -> Result<Out, DeliveryStopped>
Reads the host’s state and the termination together, under the lock.
read must not notify anyone and must not drop a value that can re-enter this multicast:
it runs under the lock. Returns DeliveryStopped, without running read, once the
delivery has stopped.
Sourcepub fn update<Out, DO, const EVENTS_DECIDED: bool>(
&self,
update: impl FnOnce(&mut R, Option<&Termination<E>>) -> UpdateOutcome<T, E, Out, DO, EVENTS_DECIDED>,
) -> Result<Out, DeliveryStopped>
pub fn update<Out, DO, const EVENTS_DECIDED: bool>( &self, update: impl FnOnce(&mut R, Option<&Termination<E>>) -> UpdateOutcome<T, E, Out, DO, EVENTS_DECIDED>, ) -> Result<Out, DeliveryStopped>
Updates the host’s state and queues the events that update produced, under one lock.
update sees the termination, so it can decide whether it may emit at all, and describes
its outcome with an UpdateOutcome over the host’s events: a
Termination in that batch is what terminates the multicast,
recorded here as the action carrying it is queued. A host that emits after the termination
was queued is a bug — check the termination first, and hand the rejected event to
UpdateOutcome::with_drop_outside.
update must not notify anyone and must not drop a value that can re-enter this multicast:
it runs under the lock. Returns DeliveryStopped, without running update, once the
delivery has stopped.
Sourcepub fn send(&self, events: EventBatch<T, E>) -> Flow
pub fn send(&self, events: EventBatch<T, E>) -> Flow
Queues events for every observer, dropping them outside the lock once terminated.
Returns whether the multicast still accepts events, which is Flow::Stop only once it
has terminated: a multicast with no subscriber left is still open, and a subscriber that
stops takes only itself away. This is Self::update for a host that reads nothing and
decides nothing.
Sourcepub fn subscribe(
self,
observer: impl Observer<T, E> + MaybeSend + 'or,
) -> Option<MulticastDisposal<'or, T, E, R>>
pub fn subscribe( self, observer: impl Observer<T, E> + MaybeSend + 'or, ) -> Option<MulticastDisposal<'or, T, E, R>>
Subscribes observer, replaying nothing and terminating it at once when already terminated.
Sourcepub fn subscribe_with(
self,
observer: impl Observer<T, E> + MaybeSend + 'or,
admit: impl FnOnce(&mut R, Option<&Termination<E>>) -> Admission<T, E>,
) -> Option<MulticastDisposal<'or, T, E, R>>
pub fn subscribe_with( self, observer: impl Observer<T, E> + MaybeSend + 'or, admit: impl FnOnce(&mut R, Option<&Termination<E>>) -> Admission<T, E>, ) -> Option<MulticastDisposal<'or, T, E, R>>
Subscribes observer, letting the host decide what it observes first, under the lock.
Reading the host’s state, handing out the id and queueing the entry are one step, so the
values admit snapshots are exactly the ones the newcomer missed: see the module
documentation. admit runs under the lock and must not notify anyone.
Returns the disposal of the subscription, or None when the observer did not join: it
has then already been notified, outside the lock.