diff options
| author | Oliver Rockstedt <[email protected]> | 2024-05-22 14:54:09 +0200 |
|---|---|---|
| committer | Oliver Rockstedt <[email protected]> | 2024-05-22 14:54:09 +0200 |
| commit | bbeba7f014b383568e999650f0d954a33955ce73 (patch) | |
| tree | df92d995036587cc8f26b5e3525796fc30edbf92 /embassy-sync/src/channel.rs | |
| parent | 1d4cd85f71058c3574a0a99f7a85572d1d87441c (diff) | |
embassy-sync: Add clear function to all channels
Diffstat (limited to 'embassy-sync/src/channel.rs')
| -rw-r--r-- | embassy-sync/src/channel.rs | 9 |
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()) |
