Struct ExclusiveReader
pub struct ExclusiveReader<'a, T>where
T: Storable + 'static,{
waiter: Waiter<'a, T>,
}Expand description
Exclusive reader for a Storable type.
By being the sole reader for a Storable type, this reader can move the read value out.
The generic type T from the reader specifies the type of the value that is being read.
The reader allows reading the current value.
If no value for type T has been written yet, ExclusiveReader::read and
ExclusiveReader::take will return None.
§Usage
ExclusiveReader::wait_for_update allows waiting until the type is written to.
It will return immediately if an unseen value is available.
Unseen does not imply the value actually changed, just that an Actor has written a value.
A write of the same value still triggers ExclusiveReader::wait_for_update to resolve.
To illustrate:
- Writer writes 5
- Reader is woken and reads 5.
Reader waits for updates.
...
- Writer writes 5 once again.
- Reader is woken and reads 5.
...The reader is woken, even if the new value equals the old one.
The ExclusiveReader is only aware of the act of writing.
§Seen values
The reader tracks whether the current value has been “seen”.
A value is marked as seen when any read method is called, such as ExclusiveReader::read or ExclusiveReader::take.
A new write from a Writer marks the value as unseen.
ExclusiveReader::is_updated returns true if the current value is unseen.
ExclusiveReader::wait_for_update waits until an unseen value is available.
§Example
#[veecle_os_runtime::actor]
async fn foo_reader(mut reader: ExclusiveReader<'_, Foo>) -> veecle_os_runtime::Never {
loop {
let value = reader.take_updated().await;
}
}Fields§
§waiter: Waiter<'a, T>Implementations§
§impl<T> ExclusiveReader<'_, T>where
T: Storable + 'static,
impl<T> ExclusiveReader<'_, T>where
T: Storable + 'static,
pub fn read<U>(
&mut self,
f: impl FnOnce(Option<&<T as Storable>::DataType>) -> U,
) -> U
Available on crate feature data-support-can only.
pub fn read<U>( &mut self, f: impl FnOnce(Option<&<T as Storable>::DataType>) -> U, ) -> U
data-support-can only.Reads the current value of a type.
Marks the current value as seen. This method takes a closure to ensure the reference is not held across await points.
pub async fn read_updated<U>(
&mut self,
f: impl FnOnce(&<T as Storable>::DataType) -> U,
) -> U
Available on crate feature data-support-can only.
pub async fn read_updated<U>( &mut self, f: impl FnOnce(&<T as Storable>::DataType) -> U, ) -> U
data-support-can only.Reads the next unseen value of a type.
Waits until an unseen value is available, then reads it. Marks the current value as seen. This method takes a closure to ensure the reference is not held across await points.
pub fn read_cloned(&mut self) -> Option<<T as Storable>::DataType>
Available on crate feature data-support-can only.
pub fn read_cloned(&mut self) -> Option<<T as Storable>::DataType>
data-support-can only.Reads and clones the current value.
Marks the current value as seen.
This is a wrapper around Self::read that additionally clones the value.
You can use it instead of reader.read(|c| c.clone()).
pub async fn read_updated_cloned(&mut self) -> <T as Storable>::DataType
Available on crate feature data-support-can only.
pub async fn read_updated_cloned(&mut self) -> <T as Storable>::DataType
data-support-can only.Reads and clones the next unseen value.
Waits until an unseen value is available, then reads it.
Marks the current value as seen.
This is a wrapper around Self::read_updated that additionally clones the value.
You can use it instead of reader.read_updated(|c| c.clone()).
pub fn is_updated(&self) -> bool
Available on crate feature data-support-can only.
pub fn is_updated(&self) -> bool
data-support-can only.Returns true if an unseen value is available.
A value becomes “seen” after calling read, read_updated,
take, take_updated, or similar methods.
pub async fn wait_for_update(&mut self) -> &mut ExclusiveReader<'_, T>
Available on crate feature data-support-can only.
pub async fn wait_for_update(&mut self) -> &mut ExclusiveReader<'_, T>
data-support-can only.pub fn take(&mut self) -> Option<<T as Storable>::DataType>
Available on crate feature data-support-can only.
pub fn take(&mut self) -> Option<<T as Storable>::DataType>
data-support-can only.Takes the current value of the type, leaving behind None.
Marks the current value as seen.
pub async fn take_updated(&mut self) -> <T as Storable>::DataType
Available on crate feature data-support-can only.
pub async fn take_updated(&mut self) -> <T as Storable>::DataType
data-support-can only.Takes the next unseen value of the type, leaving behind None.
Waits until an unseen value is available, then takes it. Marks the current value as seen.
Trait Implementations§
§impl<T> CombinableReader for ExclusiveReader<'_, T>where
T: Storable,
impl<T> CombinableReader for ExclusiveReader<'_, T>where
T: Storable,
§type ToBeRead = Option<<T as Storable>::DataType>
type ToBeRead = Option<<T as Storable>::DataType>
CombineReaders::read callback.