Expand description
Runtime-agnostic priority semaphore.
This crate provides PrioritySemaphore, an asynchronous semaphore where
waiters supply a signed priority. Higher priorities are granted returned
permits before lower ones, and equal priorities use FIFO order. The
implementation uses only the standard Future/Waker contract and does
not depend on a particular async runtime.
use std::sync::Arc;
use priority_semaphore::PrioritySemaphore;
let semaphore = Arc::new(PrioritySemaphore::new(4));
let permit = semaphore.acquire(10).await.unwrap();
// The permit is returned automatically, including during unwinding.
drop(permit);Macros§
- doc_cfg
- Conditionally add
#[doc(cfg(feature = $feat))].
Structs§
- Acquire
Future - Future returned by
PrioritySemaphore::acquire. - Permit
- Returned by successful acquire; releases permit on
Drop. - Priority
Semaphore - A runtime-independent, priority-aware asynchronous semaphore.
Enums§
- Acquire
Error - Returned by async
acquire. - TryAcquire
Error - Returned by
try_acquirewhen no permits are immediately available.
Type Aliases§
- Priority
- Priority value used by the semaphore.