pub struct Reactive<T> { /* private fields */ }std only.Expand description
A ReactiveRepr value with lock-free reads and a race-free typed
change signal.
Reactive::get is a plain atomic load. Reactive::watch hands out a
Changed whose Changed::changed awaits the next change and returns the
new value. tokio’s watch handles the wakeup race, versioning, and multiple
independent subscribers.
The value is held in the atomic (for lock-free reads) and carried on the
watch (so changed() can return it without a separate read). set stores
the atomic and then sends, which is a no-op when nobody is subscribed, so
an idle value costs nothing beyond the atomic store.
Implementations§
Source§impl<T: ReactiveRepr> Reactive<T>
impl<T: ReactiveRepr> Reactive<T>
Sourcepub fn watch(&self) -> Changed<T>
pub fn watch(&self) -> Changed<T>
Subscribe to changes. Hold the returned Changed and loop
Changed::changed to observe every change, its watch cursor is
persistent, so no edge is missed (unlike re-subscribing per await).