This commit is contained in:
Scott Mabin
2023-11-18 15:08:16 +00:00
parent f482a105b8
commit 5a60024af7
2 changed files with 6 additions and 1 deletions

View File

@ -323,7 +323,9 @@ where
/// buffer is full, attempts to `send` new messages will wait until a message is
/// received from the channel.
///
/// All data sent will become available in the same order as it was sent.
/// Sent data may be reordered based on their priorty within the channel.
/// For example, in a [`Max`](heapless::binary_heap::Max) [`PriorityChannel`]
/// containing `u32`'s, data sent in the following order `[1, 2, 3]` will be recieved as `[3, 2, 1]`.
pub struct PriorityChannel<M, T, K, const N: usize>
where
T: Ord,
@ -509,8 +511,10 @@ mod tests {
// 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(2).is_ok());
assert!(c.try_send(3).is_ok());
assert_eq!(c.try_receive().unwrap(), 3);
assert_eq!(c.try_receive().unwrap(), 2);
assert_eq!(c.try_receive().unwrap(), 1);
}