Skip to main content

priority_semaphore/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![forbid(unsafe_code)]
3#![deny(missing_docs)]
4
5//! Runtime-agnostic priority semaphore.
6//!
7//! This crate provides [`PrioritySemaphore`], an asynchronous semaphore where
8//! waiters supply a signed priority. Higher priorities are granted returned
9//! permits before lower ones, and equal priorities use FIFO order. The
10//! implementation uses only the standard `Future`/`Waker` contract and does
11//! not depend on a particular async runtime.
12//!
13//! ```rust
14//! use std::sync::Arc;
15//! use priority_semaphore::PrioritySemaphore;
16//!
17//! # #[tokio::main]
18//! # async fn main() {
19//! let semaphore = Arc::new(PrioritySemaphore::new(4));
20//! let permit = semaphore.acquire(10).await.unwrap();
21//! // The permit is returned automatically, including during unwinding.
22//! drop(permit);
23//! # }
24//! ```
25
26extern crate alloc;
27#[cfg(feature = "std")]
28extern crate std;
29
30mod error;
31mod lock;
32mod permit;
33mod queue;
34mod semaphore;
35mod util;
36mod waiter;
37
38pub use crate::error::{AcquireError, TryAcquireError};
39pub use crate::permit::Permit;
40pub use crate::semaphore::{Priority, PrioritySemaphore};
41pub use crate::waiter::AcquireFuture;