Skip to main content

SerializedMulticast

Struct SerializedMulticast 

Source
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>

Source

pub fn idle(host: R) -> Self

Starts with no observer, no termination, and the host’s state parked in the resources.

Source§

impl<'or, T, E, R> SerializedMulticast<'or, T, E, R>
where T: Clone, E: Clone,

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'or, T, E, R> Clone for SerializedMulticast<'or, T, E, R>
where SerializedDelivery<Action<'or, T, E>, E, Subscribers<'or, T, E>, Resources<E, R>>: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'or, T, E, R> Debug for SerializedMulticast<'or, T, E, R>
where SerializedDelivery<Action<'or, T, E>, E, Subscribers<'or, T, E>, Resources<E, R>>: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'or, T, E, R> Freeze for SerializedMulticast<'or, T, E, R>
where SerializedDelivery<Action<'or, T, E>, E, Subscribers<'or, T, E>, Resources<E, R>>: Freeze,

§

impl<'or, T, E, R> RefUnwindSafe for SerializedMulticast<'or, T, E, R>
where SerializedDelivery<Action<'or, T, E>, E, Subscribers<'or, T, E>, Resources<E, R>>: RefUnwindSafe,

§

impl<'or, T, E, R> Send for SerializedMulticast<'or, T, E, R>
where SerializedDelivery<Action<'or, T, E>, E, Subscribers<'or, T, E>, Resources<E, R>>: Send,

§

impl<'or, T, E, R> Sync for SerializedMulticast<'or, T, E, R>
where SerializedDelivery<Action<'or, T, E>, E, Subscribers<'or, T, E>, Resources<E, R>>: Sync,

§

impl<'or, T, E, R> Unpin for SerializedMulticast<'or, T, E, R>
where SerializedDelivery<Action<'or, T, E>, E, Subscribers<'or, T, E>, Resources<E, R>>: Unpin,

§

impl<'or, T, E, R> UnsafeUnpin for SerializedMulticast<'or, T, E, R>
where SerializedDelivery<Action<'or, T, E>, E, Subscribers<'or, T, E>, Resources<E, R>>: UnsafeUnpin,

§

impl<'or, T, E, R> UnwindSafe for SerializedMulticast<'or, T, E, R>
where SerializedDelivery<Action<'or, T, E>, E, Subscribers<'or, T, E>, Resources<E, R>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.