pub struct Live<T> { /* private fields */ }Expand description
A typed view of one projection of the current configuration.
A never-dynamic consumer can hold a plain T; a dynamic one holds Live<T> and never learns
whether it is fixed or tracking the live config. Read the view’s cached snapshot with Deref;
wait for and receive the next selected update with changed.
For a dynamic view, Deref does not perform a fresh read from the shared configuration. It
returns the last snapshot processed by this view. If the configuration advances before this
view awaits changed, Deref continues to return the older snapshot until changed processes
the notification.
Implementations§
Source§impl<T: Clone + PartialEq + 'static> Live<T>
impl<T: Clone + PartialEq + 'static> Live<T>
Sourcepub fn new_dynamic(
cell: Arc<ArcSwap<SalukiConfiguration>>,
tick: Receiver<()>,
project: impl for<'a> Fn(&'a SalukiConfiguration) -> &'a T + Send + Sync + 'static,
) -> Self
pub fn new_dynamic( cell: Arc<ArcSwap<SalukiConfiguration>>, tick: Receiver<()>, project: impl for<'a> Fn(&'a SalukiConfiguration) -> &'a T + Send + Sync + 'static, ) -> Self
Creates a view that re-projects the shared configuration after accepted updates.
The projection selects the subtree this view owns. The initial projected value is captured
immediately; later calls to changed load and project the shared configuration, then update
this view’s local snapshot. Until changed processes a notification, Deref continues to
return the previous snapshot even if the shared configuration has advanced.
Sourcepub async fn changed(&mut self) -> T
pub async fn changed(&mut self) -> T
Waits for the projected value to change and returns the new value.
The notification only says that the shared source may have changed. This method loads the
source, applies the projection, compares it with this view’s snapshot, and keeps waiting if
the selected value is unchanged. It parks forever when Fixed or the channel is closed, so
a caller can select! on it unconditionally. The returned value and Deref reflect the
same processed snapshot. This is a state-change watcher, not a fresh-read API or an event
history: multiple source updates may be coalesced before this view processes them.
Sourcepub fn project<U>(
&self,
f: impl for<'a> Fn(&'a T) -> &'a U + Send + Sync + 'static,
) -> Live<U>
pub fn project<U>( &self, f: impl for<'a> Fn(&'a T) -> &'a U + Send + Sync + 'static, ) -> Live<U>
Creates a child view by composing this view’s projection with f.
Use this when code already has a broad Live<T> but does not have the
ConfigurationSystem needed to create a narrower view
directly. A dynamic child shares the source and receives its own notification cursor and
snapshot; it wakes only when the selected child value changes. A fixed child is projected
once and remains fixed.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Live<T>where
T: Freeze,
impl<T> !RefUnwindSafe for Live<T>
impl<T> Send for Live<T>where
T: Send,
impl<T> Sync for Live<T>where
T: Sync,
impl<T> Unpin for Live<T>where
T: Unpin,
impl<T> !UnwindSafe for Live<T>
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§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
Access::load.