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 @@ //! A queue for sending values between asynchronous tasks. //! //! Similar to a [`Channel`](crate::channel::Channel), however [`PriorityChannel`] sifts higher priority items to the front of the queue. +//! Priority is determined by the `Ord` trait. Priority behavior is determined by the [`Kind`](heapless::binary_heap::Kind) parameter of the channel. use core::cell::RefCell; use core::future::Future; @@ -628,6 +629,16 @@ mod tests { assert_eq!(capacity(&c), 0); } + #[test] + fn send_priority() { + // Prio channel with kind `Max` sifts larger numbers to the front of the queue + let mut c = ChannelState::::new(); + assert!(c.try_send(1).is_ok()); + assert!(c.try_send(3).is_ok()); + assert_eq!(c.try_receive().unwrap(), 3); + assert_eq!(c.try_receive().unwrap(), 1); + } + #[test] fn receiving_once_with_one_send() { let mut c = ChannelState::::new();