priority-channel

Crates.iopriority-channel
lib.rspriority-channel
version0.1.1
created_at2026-01-16 05:46:44.809042+00
updated_at2026-01-16 05:49:17.735346+00
descriptionAn async channel supporting priority, allowing stealing and preserving the message order.
homepagehttps://github.com/wtdcode/priority-channel-rs
repositoryhttps://github.com/wtdcode/priority-channel-rs
max_upload_size
id2047965
size31,840
lazymio (wtdcode)

documentation

README

Priority Channel

Yet another async priority channel implementation.

Features:

  • Unlike common implementation using BinaryHeap, priority-channel wraps a BtreeMap<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));
}

Credits

Commit count: 0

cargo fmt