#mpmc #mpsc #spmc #chan #futures


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

1 unstable release

0.1.0 Oct 22, 2021

#797 in Asynchronous

Download history 37347/week @ 2023-08-16 35231/week @ 2023-08-23 34262/week @ 2023-08-30 36587/week @ 2023-09-06 38448/week @ 2023-09-13 39521/week @ 2023-09-20 40033/week @ 2023-09-27 44974/week @ 2023-10-04 43123/week @ 2023-10-11 40765/week @ 2023-10-18 42290/week @ 2023-10-25 46260/week @ 2023-11-01 42724/week @ 2023-11-08 42238/week @ 2023-11-15 40744/week @ 2023-11-22 33291/week @ 2023-11-29

166,382 downloads per month
Used in 21 crates (2 directly)

Apache-2.0 OR MIT

506 lines


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.


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