pub struct ConcurrencyBudget { /* private fields */ }Expand description
Shared admission gate for CPU-bound (and future multi-GET) work.
Implementations§
Source§impl ConcurrencyBudget
impl ConcurrencyBudget
Sourcepub fn new(max: usize) -> Self
pub fn new(max: usize) -> Self
Build a budget from a resolved permit count (0 is invalid; use
resolve_max_concurrency first).
Sourcepub fn from_configured(configured: u32) -> Self
pub fn from_configured(configured: u32) -> Self
Resolve auto/override then build.
Sourcepub fn available_permits(&self) -> usize
pub fn available_permits(&self) -> usize
Permits currently free (observability / doctor).
Sourcepub fn semaphore(&self) -> Arc<Semaphore> ⓘ
pub fn semaphore(&self) -> Arc<Semaphore> ⓘ
Clone of the inner semaphore for acquire_owned at spawn sites.
Sourcepub async fn acquire_owned(&self) -> AppResult<OwnedSemaphorePermit>
pub async fn acquire_owned(&self) -> AppResult<OwnedSemaphorePermit>
Acquire one permit (RAII). Prefer Self::run_cpu_bound for spawn paths.
§Errors
Returns crate::error::ErrorKind::Internal when the semaphore is closed (should not
happen in the one-shot lifecycle). The AcquireError is preserved as
std::error::Error::source.
Sourcepub async fn run_cpu_bound<F, T>(&self, f: F) -> AppResult<T>
pub async fn run_cpu_bound<F, T>(&self, f: F) -> AppResult<T>
Run CPU / blocking work on Tokio’s blocking pool under this budget.
Acquires a permit before spawn_blocking; the permit is held until the
closure returns (dropped inside the blocking thread).
§Errors
Propagates closure errors. Maps worker panic to crate::error::ErrorKind::Internal
and abort/cancel to crate::error::ErrorKind::Interrupted.