Struct Reader
pub struct Reader<'a, T, const N: usize>where
T: Storable + 'static,{
slot: Pin<&'a Slot<T, N>>,
waiter: Waiter<'a>,
}Expand description
Exclusive reader for Storable types from an mpsc slot.
Reads values written by multiple Writers for the same type.
Reading a value takes ownership from the slot, marking it as consumed.
The generic type T specifies the type of the value being read.
The const generic N specifies the maximum number of writers.
§Usage
Reader::take_all_updated reads all available value via closure, waiting if no values are currently available.
Reader::take_all reads all available value via closure.
Reader::take_one returns one value if available.
§Examples
// Using `take_all` to process all available values.
#[veecle_os_runtime::actor]
async fn command_handler<const N: usize>(mut reader: Reader<'_, Command, N>) -> veecle_os_runtime::Never {
loop {
reader.wait_for_update().await;
reader.take_all(|command| {
// Process the command.
});
}
}Fields§
§slot: Pin<&'a Slot<T, N>>§waiter: Waiter<'a>Implementations§
§impl<T, const N: usize> Reader<'_, T, N>where
T: Storable + 'static,
impl<T, const N: usize> Reader<'_, T, N>where
T: Storable + 'static,
pub fn is_updated(&self) -> bool
Available on crate feature data-support-can only.
pub fn is_updated(&self) -> bool
data-support-can only.pub async fn wait_for_update(&mut self) -> &mut Reader<'_, T, N>
Available on crate feature data-support-can only.
pub async fn wait_for_update(&mut self) -> &mut Reader<'_, T, N>
data-support-can only.Waits for unseen values to become available.
This future resolving does not imply that previous_value != new_value, just that a
Writer has written a value of T since the last read operation.
Returns &mut Self to allow chaining method calls.
pub fn take_one(&mut self) -> Option<<T as Storable>::DataType>
Available on crate feature data-support-can only.
pub fn take_one(&mut self) -> Option<<T as Storable>::DataType>
data-support-can only.Takes the next available value, returns None if none are available.
pub fn take_all(&mut self, f: impl FnMut(<T as Storable>::DataType))
Available on crate feature data-support-can only.
pub fn take_all(&mut self, f: impl FnMut(<T as Storable>::DataType))
data-support-can only.Reads all available values.
Takes ownership of each value and passes it to f.
pub async fn take_all_updated(
&mut self,
f: impl FnMut(<T as Storable>::DataType),
)
Available on crate feature data-support-can only.
pub async fn take_all_updated( &mut self, f: impl FnMut(<T as Storable>::DataType), )
data-support-can only.Reads all available values, waiting if none are available.
Takes ownership of each value and passes it to f.
When no values are available, waits for new writes and returns after reading at least one value.