pub struct WatchManager { /* private fields */ }Expand description
Manages watch subscriptions for change polling.
Watches are keyed by a UUID watch ID and owned by a specific user. The manager enforces global and per-user watch limits, per-watch entity ID limits, and provides an entity encoding cache for efficient WebSocket server-push serialization.
Implementations§
Source§impl WatchManager
impl WatchManager
Sourcepub fn subscribe(
&self,
username: &str,
ids: Vec<String>,
graph_version: u64,
) -> Result<String, String>
pub fn subscribe( &self, username: &str, ids: Vec<String>, graph_version: u64, ) -> Result<String, String>
Subscribe to changes on a set of entity IDs.
Returns the watch ID, or an error if a growth cap would be exceeded.
Sourcepub fn poll(
&self,
watch_id: &str,
username: &str,
graph: &SharedGraph,
) -> Option<Vec<HDict>>
pub fn poll( &self, watch_id: &str, username: &str, graph: &SharedGraph, ) -> Option<Vec<HDict>>
Poll for changes since the last poll.
Returns the current state of watched entities that have changed,
or None if the watch ID is not found or the caller is not the owner.
Sourcepub fn unsubscribe(&self, watch_id: &str, username: &str) -> bool
pub fn unsubscribe(&self, watch_id: &str, username: &str) -> bool
Unsubscribe a watch by ID.
Returns true if the watch existed, was owned by username, and was removed.
Sourcepub fn add_ids(&self, watch_id: &str, username: &str, ids: Vec<String>) -> bool
pub fn add_ids(&self, watch_id: &str, username: &str, ids: Vec<String>) -> bool
Add entity IDs to an existing watch.
Returns true if the watch exists, is owned by username, and
the addition would not exceed the per-watch entity ID limit.
Sourcepub fn remove_ids(&self, watch_id: &str, username: &str, ids: &[String]) -> bool
pub fn remove_ids(&self, watch_id: &str, username: &str, ids: &[String]) -> bool
Remove specific entity IDs from an existing watch.
Returns true if the watch exists and is owned by username.
If all IDs are removed, the watch remains but with an empty entity set.
Sourcepub fn get_ids(&self, watch_id: &str) -> Option<Vec<String>>
pub fn get_ids(&self, watch_id: &str) -> Option<Vec<String>>
Return the list of entity IDs for a given watch.
Returns None if the watch does not exist.
Sourcepub fn encode_cached(
&self,
ref_val: &str,
graph_version: u64,
entity: &HDict,
) -> Value
pub fn encode_cached( &self, ref_val: &str, graph_version: u64, entity: &HDict, ) -> Value
Encode an entity using the cache. Returns cached value if the entity version hasn’t changed; otherwise encodes and caches the result.
Sourcepub fn all_watched_ids(&self) -> HashSet<String>
pub fn all_watched_ids(&self) -> HashSet<String>
Get the IDs of all entities watched by any watch, for server-push change detection.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for WatchManager
impl !RefUnwindSafe for WatchManager
impl Send for WatchManager
impl Sync for WatchManager
impl Unpin for WatchManager
impl UnsafeUnpin for WatchManager
impl UnwindSafe for WatchManager
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more