| Crates.io | ranked-semaphore |
| lib.rs | ranked-semaphore |
| version | 0.1.4 |
| created_at | 2025-06-27 16:04:21.025982+00 |
| updated_at | 2025-07-07 02:58:38.883197+00 |
| description | A high-performance ranked semaphore with priority support |
| homepage | |
| repository | https://github.com/YeungKC/ranked-semaphore |
| max_upload_size | |
| id | 1728902 |
| size | 194,564 |
A priority-aware semaphore for async Rust.
use ranked_semaphore::RankedSemaphore;
#[tokio::main]
async fn main() {
// Create a semaphore with 3 permits, FIFO strategy
let sem = RankedSemaphore::new_fifo(3);
// Acquire a permit (default priority)
let permit = sem.acquire().await.unwrap();
// Acquire with custom priority
let high = sem.acquire_with_priority(10).await.unwrap();
// Release permits automatically on drop
drop(permit);
drop(high);
}
use ranked_semaphore::{RankedSemaphore, PriorityConfig, QueueStrategy};
use std::sync::Arc;
let config = PriorityConfig::new()
.default_strategy(QueueStrategy::Fifo)
.exact(10, QueueStrategy::Lifo);
let limiter = Arc::new(RankedSemaphore::new_with_config(2, config));
let _admin = limiter.acquire_with_priority(10).await.unwrap();
let _guest = limiter.acquire_with_priority(0).await.unwrap();
The semaphore works with any async runtime. Runtime compatibility is ensured through comprehensive integration tests:
# Test Tokio runtime integration
cargo test --test runtime_tokio_test
# Test async-std runtime integration
cargo test --test runtime_async_std_test
# Test smol runtime integration
cargo test --test runtime_smol_test
# Test futures runtime integration
cargo test --test runtime_futures_test
These tests serve as both verification and usage examples for each runtime.
MIT