aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-sync/src/priority_channel.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/embassy-sync/src/priority_channel.rs b/embassy-sync/src/priority_channel.rs
index 1f4d8667c..a4eda7fbc 100644
--- a/embassy-sync/src/priority_channel.rs
+++ b/embassy-sync/src/priority_channel.rs
@@ -72,6 +72,17 @@ where
72 self.channel.poll_ready_to_send(cx) 72 self.channel.poll_ready_to_send(cx)
73 } 73 }
74 74
75 /// Removes the elements from the channel that satisfy the predicate.
76 ///
77 /// See [`PriorityChannel::remove_if()`]
78 pub fn remove_if<F>(&self, predicate: F)
79 where
80 F: Fn(&T) -> bool,
81 T: Clone,
82 {
83 self.channel.remove_if(predicate)
84 }
85
75 /// Returns the maximum number of elements the channel can hold. 86 /// Returns the maximum number of elements the channel can hold.
76 /// 87 ///
77 /// See [`PriorityChannel::capacity()`] 88 /// See [`PriorityChannel::capacity()`]
@@ -189,6 +200,17 @@ where
189 self.channel.poll_receive(cx) 200 self.channel.poll_receive(cx)
190 } 201 }
191 202
203 /// Removes the elements from the channel that satisfy the predicate.
204 ///
205 /// See [`PriorityChannel::remove_if()`]
206 pub fn remove_if<F>(&self, predicate: F)
207 where
208 F: Fn(&T) -> bool,
209 T: Clone,
210 {
211 self.channel.remove_if(predicate)
212 }
213
192 /// Returns the maximum number of elements the channel can hold. 214 /// Returns the maximum number of elements the channel can hold.
193 /// 215 ///
194 /// See [`PriorityChannel::capacity()`] 216 /// See [`PriorityChannel::capacity()`]
@@ -534,6 +556,26 @@ where
534 self.lock(|c| c.try_receive()) 556 self.lock(|c| c.try_receive())
535 } 557 }
536 558
559 /// Removes elements from the channel based on the given predicate.
560 pub fn remove_if<F>(&self, predicate: F)
561 where
562 F: Fn(&T) -> bool,
563 T: Clone,
564 {
565 self.lock(|c| {
566 let mut new_heap = BinaryHeap::<T, K, N>::new();
567 for item in c.queue.iter() {
568 if !predicate(item) {
569 match new_heap.push(item.clone()) {
570 Ok(_) => (),
571 Err(_) => panic!("Error pushing item to heap"),
572 }
573 }
574 }
575 c.queue = new_heap;
576 });
577 }
578
537 /// Returns the maximum number of elements the channel can hold. 579 /// Returns the maximum number of elements the channel can hold.
538 pub const fn capacity(&self) -> usize { 580 pub const fn capacity(&self) -> usize {
539 N 581 N