Skip to content

wtdcode/priority-channel-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages