async-priority-channel

Crates.ioasync-priority-channel
lib.rsasync-priority-channel
version0.2.0
sourcesrc
created_at2021-10-22 00:40:38.955341
updated_at2024-01-04 04:05:26.218219
descriptionAn async channel where pending messages are delivered in order of priority
homepagehttps://github.com/rmcgibbo/async-priority-channel
repositoryhttps://github.com/rmcgibbo/async-priority-channel
max_upload_size
id469140
size53,509
Robert T. McGibbon (rmcgibbo)

documentation

https://docs.rs/async-priority-channel

README

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

Commit count: 59

cargo fmt