docs and simple test for priority
This commit is contained in:
parent
270ec324b0
commit
2efa73f431
1 changed files with 11 additions and 0 deletions
|
@ -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::<u32, Max, 3>::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::<u32, Max, 3>::new();
|
||||
|
|
Loading…
Reference in a new issue