pub struct Cache<T> { /* private fields */ }Expand description
A simple caching struct that can be used to locally maintain a synchronized state with an actor
Implementations§
Source§impl<T> Cache<T>
impl<T> Cache<T>
Sourcepub fn has_updates(&self) -> bool
pub fn has_updates(&self) -> bool
Returns if any new updates are received
Sourcepub fn get_newest(&mut self) -> &T
pub fn get_newest(&mut self) -> &T
Returns the newest value available, even if the channel is closed Note that when the cache is initialized with a default value, this might return the default while the actor has a different value
Sourcepub fn get_current(&self) -> &T
pub fn get_current(&self) -> &T
Returns the current value held by the cache, without synchronizing with the actor
Sourcepub async fn recv_newest(&mut self) -> Result<&T, CacheRecvNewestError>
pub async fn recv_newest(&mut self) -> Result<&T, CacheRecvNewestError>
Receive the newest updated value broadcasted by the actor, discarding any older messages. The first time it will return its current value immediately After that, it might wait indefinitely for a new update Note that when the cache is initialized with a default value, this might return the default while the actor has a different value
Sourcepub async fn recv(&mut self) -> Result<&T, CacheRecvError>
pub async fn recv(&mut self) -> Result<&T, CacheRecvError>
Receive the last updated value broadcasted by the actor (FIFO). The first time it will return its current value immediately After that, it might wait indefinitely for a new update Note that when the cache is initialized with a default value, this might return the default while the actor has a different value
Sourcepub fn try_recv_newest(&mut self) -> Result<Option<&T>, CacheRecvNewestError>
pub fn try_recv_newest(&mut self) -> Result<Option<&T>, CacheRecvNewestError>
Try to receive the newest updated value broadcasted by the actor, discarding any older messages. The first time it will return its initialized value, even if no updates are present. After that, lacking updates will return None. Note that when the cache is initialized with a default value, this might return None while the actor has a value
Sourcepub fn try_recv(&mut self) -> Result<Option<&T>, CacheRecvError>
pub fn try_recv(&mut self) -> Result<Option<&T>, CacheRecvError>
Try to receive the last updated value broadcasted by the actor once (FIFO). The first time it will return its initialized value, even if no updates are present. After that, lacking updates will return None. Note that when the cache is initialized with a default value, this might return None while the actor has a value