pub struct Producer<T> { /* private fields */ }Expand description
Publishes a JSON value over a track, choosing snapshots and deltas automatically.
Cheaply clonable: clones share one underlying track and publishing state, like other MoQ producers.
Implementations§
Source§impl<T> Producer<T>
impl<T> Producer<T>
Sourcepub fn consume(&self) -> TrackConsumer
pub fn consume(&self) -> TrackConsumer
Create a subscriber for the underlying track.
Source§impl<T: Serialize> Producer<T>
impl<T: Serialize> Producer<T>
Sourcepub fn new(track: TrackProducer, config: Config) -> Self
pub fn new(track: TrackProducer, config: Config) -> Self
Create a producer that publishes to the given track.
Sourcepub fn update(&mut self, value: &T) -> Result<()>
pub fn update(&mut self, value: &T) -> Result<()>
Publish a new value, emitting a snapshot or a delta automatically.
Does nothing if the value is unchanged from the previous publish.
Sourcepub fn lock(&mut self) -> Guard<'_, T>where
T: Default + DeserializeOwned,
pub fn lock(&mut self) -> Guard<'_, T>where
T: Default + DeserializeOwned,
Lock the current value for in-place editing, publishing on drop.
The returned Guard derefs to the last-published value (or T::default() if nothing has
been published yet). Editing it through DerefMut marks the guard dirty; when a dirty
guard drops it publishes the result, a no-op if unchanged.
This is the counterpart to a callback: hold the guard, mutate, drop. The guard holds the
producer’s lock for its lifetime, so independent owners are serialized: each one starts from
the latest value and their changes compose instead of clobbering. Don’t hold a guard across
an .await, since that keeps the lock held while suspended.