aboutsummaryrefslogtreecommitdiff
path: root/embassy-sync/src/channel.rs
diff options
context:
space:
mode:
authorOliver Rockstedt <[email protected]>2024-05-22 14:54:09 +0200
committerOliver Rockstedt <[email protected]>2024-05-22 14:54:09 +0200
commitbbeba7f014b383568e999650f0d954a33955ce73 (patch)
treedf92d995036587cc8f26b5e3525796fc30edbf92 /embassy-sync/src/channel.rs
parent1d4cd85f71058c3574a0a99f7a85572d1d87441c (diff)
embassy-sync: Add clear function to all channels
Diffstat (limited to 'embassy-sync/src/channel.rs')
-rw-r--r--embassy-sync/src/channel.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs
index b124a885f..55ac5fb66 100644
--- a/embassy-sync/src/channel.rs
+++ b/embassy-sync/src/channel.rs
@@ -477,6 +477,10 @@ impl<T, const N: usize> ChannelState<T, N> {
477 } 477 }
478 } 478 }
479 479
480 fn clear(&mut self) {
481 self.queue.clear();
482 }
483
480 fn len(&self) -> usize { 484 fn len(&self) -> usize {
481 self.queue.len() 485 self.queue.len()
482 } 486 }
@@ -632,6 +636,11 @@ where
632 N - self.len() 636 N - self.len()
633 } 637 }
634 638
639 /// Clears all elements in the channel.
640 pub fn clear(&self) {
641 self.lock(|c| c.clear());
642 }
643
635 /// Returns the number of elements currently in the channel. 644 /// Returns the number of elements currently in the channel.
636 pub fn len(&self) -> usize { 645 pub fn len(&self) -> usize {
637 self.lock(|c| c.len()) 646 self.lock(|c| c.len())