#async-channel #future #bounded-channel #unbounded-channel #mpmc #spmc #mpsc

async-priority-channel

An async channel where pending messages are delivered in order of priority

2 unstable releases

0.2.0 Jan 4, 2024
0.1.0 Oct 22, 2021

#881 in Concurrency

Download history 11973/week @ 2024-07-22 10156/week @ 2024-07-29 11296/week @ 2024-08-05 11509/week @ 2024-08-12 11794/week @ 2024-08-19 12856/week @ 2024-08-26 12119/week @ 2024-09-02 12219/week @ 2024-09-09 12093/week @ 2024-09-16 15502/week @ 2024-09-23 12258/week @ 2024-09-30 8035/week @ 2024-10-07 10616/week @ 2024-10-14 11025/week @ 2024-10-21 11132/week @ 2024-10-28 12326/week @ 2024-11-04

45,697 downloads per month
Used in 46 crates (5 directly)

Apache-2.0 OR MIT

26KB
510 lines

async-priority-channel

Build License Cargo Documentation

An async channel where pending messages are delivered in order of priority.

There are two kinds of channels:

  1. Bounded channel with limited capacity.
  2. Unbounded channel with unlimited capacity.

A channel has the Sender and Receiver side. Both sides are cloneable and can be shared among multiple threads. When sending, you pass in a message and its priority. When receiving, you'll get back the pending message with the highest priotiy.

When all Senders or all Receivers are dropped, the channel becomes closed. When a channel is closed, no more messages can be sent, but remaining messages can still be received.

The channel can also be closed manually by calling Sender::close() or Receiver::close(). The API and much of the documentation is based on async_channel.

Examples

let (s, r) = async_priority_channel::unbounded();

assert_eq!(s.send("Foo", 0).await, Ok(()));
assert_eq!(s.send("Bar", 2).await, Ok(()));
assert_eq!(s.send("Baz", 1).await, Ok(()));
assert_eq!(r.recv().await, Ok(("Bar", 2)));

License: Apache-2.0 OR MIT

Dependencies

~355KB