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/priority_channel.rs | |
| parent | 1d4cd85f71058c3574a0a99f7a85572d1d87441c (diff) | |
embassy-sync: Add clear function to all channels
Diffstat (limited to 'embassy-sync/src/priority_channel.rs')
| -rw-r--r-- | embassy-sync/src/priority_channel.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/embassy-sync/src/priority_channel.rs b/embassy-sync/src/priority_channel.rs index 2954d1b76..24c6c5a7f 100644 --- a/embassy-sync/src/priority_channel.rs +++ b/embassy-sync/src/priority_channel.rs | |||
| @@ -315,6 +315,10 @@ where | |||
| 315 | } | 315 | } |
| 316 | } | 316 | } |
| 317 | 317 | ||
| 318 | fn clear(&mut self) { | ||
| 319 | self.queue.clear(); | ||
| 320 | } | ||
| 321 | |||
| 318 | fn len(&self) -> usize { | 322 | fn len(&self) -> usize { |
| 319 | self.queue.len() | 323 | self.queue.len() |
| 320 | } | 324 | } |
| @@ -458,6 +462,11 @@ where | |||
| 458 | N - self.len() | 462 | N - self.len() |
| 459 | } | 463 | } |
| 460 | 464 | ||
| 465 | /// Clears all elements in the channel. | ||
| 466 | pub fn clear(&self) { | ||
| 467 | self.lock(|c| c.clear()); | ||
| 468 | } | ||
| 469 | |||
| 461 | /// Returns the number of elements currently in the channel. | 470 | /// Returns the number of elements currently in the channel. |
| 462 | pub fn len(&self) -> usize { | 471 | pub fn len(&self) -> usize { |
| 463 | self.lock(|c| c.len()) | 472 | self.lock(|c| c.len()) |
