mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-25 00:02:28 +00:00
embassy-sync: Add clear function to all channels
This commit is contained in:
parent
1d4cd85f71
commit
bbeba7f014
@ -7,9 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Add `capacity`, `free_capacity`, `len`, `is_empty` and `is_full` functions to `Channel`.
|
||||
- Add `capacity`, `free_capacity`, `len`, `is_empty` and `is_full` functions to `PriorityChannel`.
|
||||
- Add `capacity`, `free_capacity`, `len`, `is_empty` and `is_full` functions to `PubSubChannel`.
|
||||
- Add `capacity`, `free_capacity`, `clear`, `len`, `is_empty` and `is_full` functions to `Channel`.
|
||||
- Add `capacity`, `free_capacity`, `clear`, `len`, `is_empty` and `is_full` functions to `PriorityChannel`.
|
||||
- Add `capacity`, `free_capacity`, `clear`, `len`, `is_empty` and `is_full` functions to `PubSubChannel`.
|
||||
- Made `PubSubBehavior` sealed
|
||||
- If you called `.publish_immediate(...)` on the queue directly before, then now call `.immediate_publisher().publish_immediate(...)`
|
||||
|
||||
|
@ -477,6 +477,10 @@ impl<T, const N: usize> ChannelState<T, N> {
|
||||
}
|
||||
}
|
||||
|
||||
fn clear(&mut self) {
|
||||
self.queue.clear();
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.queue.len()
|
||||
}
|
||||
@ -632,6 +636,11 @@ where
|
||||
N - self.len()
|
||||
}
|
||||
|
||||
/// Clears all elements in the channel.
|
||||
pub fn clear(&self) {
|
||||
self.lock(|c| c.clear());
|
||||
}
|
||||
|
||||
/// Returns the number of elements currently in the channel.
|
||||
pub fn len(&self) -> usize {
|
||||
self.lock(|c| c.len())
|
||||
|
@ -315,6 +315,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn clear(&mut self) {
|
||||
self.queue.clear();
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.queue.len()
|
||||
}
|
||||
@ -458,6 +462,11 @@ where
|
||||
N - self.len()
|
||||
}
|
||||
|
||||
/// Clears all elements in the channel.
|
||||
pub fn clear(&self) {
|
||||
self.lock(|c| c.clear());
|
||||
}
|
||||
|
||||
/// Returns the number of elements currently in the channel.
|
||||
pub fn len(&self) -> usize {
|
||||
self.lock(|c| c.len())
|
||||
|
@ -173,6 +173,11 @@ impl<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usi
|
||||
CAP - self.len()
|
||||
}
|
||||
|
||||
/// Clears all elements in the channel.
|
||||
pub fn clear(&self) {
|
||||
self.inner.lock(|inner| inner.borrow_mut().clear());
|
||||
}
|
||||
|
||||
/// Returns the number of elements currently in the channel.
|
||||
pub fn len(&self) -> usize {
|
||||
self.inner.lock(|inner| inner.borrow().len())
|
||||
@ -270,6 +275,10 @@ impl<M: RawMutex, T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usi
|
||||
self.free_capacity()
|
||||
}
|
||||
|
||||
fn clear(&self) {
|
||||
self.clear();
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.len()
|
||||
}
|
||||
@ -407,6 +416,10 @@ impl<T: Clone, const CAP: usize, const SUBS: usize, const PUBS: usize> PubSubSta
|
||||
self.publisher_count -= 1;
|
||||
}
|
||||
|
||||
fn clear(&mut self) {
|
||||
self.queue.clear();
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.queue.len()
|
||||
}
|
||||
@ -460,6 +473,9 @@ trait SealedPubSubBehavior<T> {
|
||||
/// This is equivalent to `capacity() - len()`
|
||||
fn free_capacity(&self) -> usize;
|
||||
|
||||
/// Clears all elements in the channel.
|
||||
fn clear(&self);
|
||||
|
||||
/// Returns the number of elements currently in the channel.
|
||||
fn len(&self) -> usize;
|
||||
|
||||
|
@ -55,6 +55,11 @@ impl<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> Pub<'a, PSB, T> {
|
||||
self.channel.free_capacity()
|
||||
}
|
||||
|
||||
/// Clears all elements in the ***channel***.
|
||||
pub fn clear(&self) {
|
||||
self.channel.clear();
|
||||
}
|
||||
|
||||
/// Returns the number of elements currently in the ***channel***.
|
||||
pub fn len(&self) -> usize {
|
||||
self.channel.len()
|
||||
@ -155,6 +160,11 @@ impl<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> ImmediatePub<'a, PSB, T> {
|
||||
self.channel.free_capacity()
|
||||
}
|
||||
|
||||
/// Clears all elements in the ***channel***.
|
||||
pub fn clear(&self) {
|
||||
self.channel.clear();
|
||||
}
|
||||
|
||||
/// Returns the number of elements currently in the ***channel***.
|
||||
pub fn len(&self) -> usize {
|
||||
self.channel.len()
|
||||
|
@ -83,6 +83,11 @@ impl<'a, PSB: PubSubBehavior<T> + ?Sized, T: Clone> Sub<'a, PSB, T> {
|
||||
self.channel.free_capacity()
|
||||
}
|
||||
|
||||
/// Clears all elements in the ***channel***.
|
||||
pub fn clear(&self) {
|
||||
self.channel.clear();
|
||||
}
|
||||
|
||||
/// Returns the number of elements currently in the ***channel***.
|
||||
/// See [Self::available] for how many messages are available for this subscriber.
|
||||
pub fn len(&self) -> usize {
|
||||
|
Loading…
Reference in New Issue
Block a user