Struct yrs::observer::ObserverMut
source · pub struct ObserverMut<E> { /* private fields */ }
Expand description
Data structure used to handle publish/subscribe callbacks of specific type. Observers perform subscriber changes in thread-safe manner, using atomic hardware intrinsics.
Implementations§
source§impl<E> ObserverMut<E>
impl<E> ObserverMut<E>
sourcepub fn clean(&self)
pub fn clean(&self)
Cleanup already released subscriptions. Whenever a Subscription is dropped, the callback is released. However, the weak reference to callback may still be kept around until it becomes touched by operations such as Observer::subscribe or Observer::callbacks.
This method allows to perform stale callback cleanup without waiting for callbacks to be visited.
sourcepub fn subscribe<F>(&self, callback: F) -> Subscription
pub fn subscribe<F>(&self, callback: F) -> Subscription
Subscribes a callback parameter to a current Observer. Returns a subscription object which - when dropped - will unsubscribe current callback.
sourcepub fn callbacks(&self) -> Option<CallbacksMut<'_, E>>
pub fn callbacks(&self) -> Option<CallbacksMut<'_, E>>
Returns a snapshot of callbacks subscribed to this observer at the moment when this method has been called. This snapshot can be iterated over to get access to individual callbacks and trigger them.