|0.1.0||Oct 22, 2021|
#797 in Asynchronous
166,382 downloads per month
Used in 21 crates (2 directly)
An async channel where pending messages are delivered in order of priority.
There are two kinds of channels:
- Bounded channel with limited capacity.
- Unbounded channel with unlimited capacity.
A channel has the
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.
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
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