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

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

#368 in Asynchronous

Download history 42768/week @ 2024-01-22 49198/week @ 2024-01-29 47719/week @ 2024-02-05 44240/week @ 2024-02-12 43092/week @ 2024-02-19 43614/week @ 2024-02-26 47046/week @ 2024-03-04 49521/week @ 2024-03-11 49579/week @ 2024-03-18 49408/week @ 2024-03-25 49172/week @ 2024-04-01 46204/week @ 2024-04-08 47124/week @ 2024-04-15 28597/week @ 2024-04-22 15675/week @ 2024-04-29 13585/week @ 2024-05-06

110,990 downloads per month
Used in 28 crates (4 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