aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Mabin <[email protected]>2023-11-18 14:37:15 +0000
committerScott Mabin <[email protected]>2023-11-18 14:37:15 +0000
commit2efa73f4313aeaad9b65b634425b689520096b9a (patch)
tree923a599750cf0e854817a7bf7ff0af0f195fccaa
parent270ec324b0f4bdf400043bbb4023a32c6c7d94d4 (diff)
docs and simple test for priority
-rw-r--r--embassy-sync/src/priority_channel.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/embassy-sync/src/priority_channel.rs b/embassy-sync/src/priority_channel.rs
index 13c407c21..6f419aa6e 100644
--- a/embassy-sync/src/priority_channel.rs
+++ b/embassy-sync/src/priority_channel.rs
@@ -1,6 +1,7 @@
1//! A queue for sending values between asynchronous tasks. 1//! A queue for sending values between asynchronous tasks.
2//! 2//!
3//! Similar to a [`Channel`](crate::channel::Channel), however [`PriorityChannel`] sifts higher priority items to the front of the queue. 3//! Similar to a [`Channel`](crate::channel::Channel), however [`PriorityChannel`] sifts higher priority items to the front of the queue.
4//! Priority is determined by the `Ord` trait. Priority behavior is determined by the [`Kind`](heapless::binary_heap::Kind) parameter of the channel.
4 5
5use core::cell::RefCell; 6use core::cell::RefCell;
6use core::future::Future; 7use core::future::Future;
@@ -629,6 +630,16 @@ mod tests {
629 } 630 }
630 631
631 #[test] 632 #[test]
633 fn send_priority() {
634 // Prio channel with kind `Max` sifts larger numbers to the front of the queue
635 let mut c = ChannelState::<u32, Max, 3>::new();
636 assert!(c.try_send(1).is_ok());
637 assert!(c.try_send(3).is_ok());
638 assert_eq!(c.try_receive().unwrap(), 3);
639 assert_eq!(c.try_receive().unwrap(), 1);
640 }
641
642 #[test]
632 fn receiving_once_with_one_send() { 643 fn receiving_once_with_one_send() {
633 let mut c = ChannelState::<u32, Max, 3>::new(); 644 let mut c = ChannelState::<u32, Max, 3>::new();
634 assert!(c.try_send(1).is_ok()); 645 assert!(c.try_send(1).is_ok());