Yet another async priority channel implementation.
Features:
- Unlike common implementation using
BinaryHeap,priority-channelwraps aBtreeMap<P, VecDequeue<V>>which preserves the order of messages with the same priority. - Multi producers and multi receivers.
- Support both bounded and unbounded channels.
- Allow "stealing" messages when the channel is full. It is useful to avoid missing messages when producers are super fast and earlier messages tend to be expired.
- Minimal dependency on
tokio.
The tests are borrowed from async-priority-channel and most usages could refer to async-channel.
Sample:
async fn test_send_recv_2() {
let (tx, rx) = bounded(3);
tx.send(1, 1).await.unwrap();
tx.send(3, 3).await.unwrap();
tx.send(2, 2).await.unwrap();
assert_eq!(rx.recv().await.unwrap(), (3, 3));
assert_eq!(rx.recv().await.unwrap(), (2, 2));
assert_eq!(rx.recv().await.unwrap(), (1, 1));
}