#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 35853/week @ 2024-01-03 38298/week @ 2024-01-10 38757/week @ 2024-01-17 45528/week @ 2024-01-24 48222/week @ 2024-01-31 48365/week @ 2024-02-07 41932/week @ 2024-02-14 43948/week @ 2024-02-21 44416/week @ 2024-02-28 47493/week @ 2024-03-06 49967/week @ 2024-03-13 49745/week @ 2024-03-20 49041/week @ 2024-03-27 48421/week @ 2024-04-03 46518/week @ 2024-04-10 40477/week @ 2024-04-17

191,872 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

~350KB