ranked_semaphore/
lib.rs

1//! # ranked-semaphore
2//!
3//! **A priority-aware semaphore for async Rust.**
4//!
5//! ## Features
6//! - Priority scheduling: Configurable priority-based task ordering
7//! - No runtime dependency: Works with any async runtime (Tokio, async-std, smol, etc.)
8//! - Flexible queue strategies: FIFO/LIFO and custom strategy
9//!
10//! ## Quick Start
11//! ```rust
12//! use ranked_semaphore::RankedSemaphore;
13//!
14//! #[tokio::main]
15//! async fn main() {
16//!     // Create a semaphore with 3 permits, FIFO strategy
17//!     let sem = RankedSemaphore::new_fifo(3);
18//!
19//!     // Acquire a permit (default priority)
20//!     let permit = sem.acquire().await.unwrap();
21//!
22//!     // Acquire with custom priority
23//!     let high = sem.acquire_with_priority(10).await.unwrap();
24//!
25//!     // Release permits automatically on drop
26//!     drop(permit);
27//!     drop(high);
28//! }
29//! ```
30//!
31//! ## Advanced Usage
32//!
33//! Use [`PriorityConfig`] and [`QueueStrategy`] for fine-grained control:
34//!
35//! ```rust
36//! use ranked_semaphore::{RankedSemaphore, PriorityConfig, QueueStrategy};
37//! use std::sync::Arc;
38//!
39//! #[tokio::main]
40//! async fn main() {
41//!     let config = PriorityConfig::new()
42//!         .default_strategy(QueueStrategy::Fifo)
43//!         .exact(10, QueueStrategy::Lifo);
44//!
45//!     let limiter = Arc::new(RankedSemaphore::new_with_config(2, config));
46//!
47//!     let _admin = limiter.acquire_with_priority(10).await.unwrap();
48//!     let _guest = limiter.acquire_with_priority(0).await.unwrap();
49//! }
50//! ```
51//!
52//! See the [README](https://github.com/yeungkc/ranked-semaphore#readme) and [API docs](https://docs.rs/ranked-semaphore) for more details.
53#![cfg_attr(docsrs, feature(doc_cfg))]
54#![warn(missing_docs, unreachable_pub, missing_debug_implementations)]
55#![deny(rust_2018_idioms)]
56
57mod config;
58mod error;
59mod semaphore;
60mod wait_queue;
61
62pub use config::{PriorityConfig, QueueStrategy};
63pub use error::{AcquireError, TryAcquireError};
64pub use semaphore::{OwnedRankedSemaphorePermit, RankedSemaphore, RankedSemaphorePermit};
65
66pub use semaphore::{Acquire, AcquireOwned};