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.
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 ErrorKind::Internal
and abort/cancel to ErrorKind::Interrupted.
Trait Implementations§
Source§impl Clone for ConcurrencyBudget
impl Clone for ConcurrencyBudget
Source§fn clone(&self) -> ConcurrencyBudget
fn clone(&self) -> ConcurrencyBudget
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ConcurrencyBudget
impl RefUnwindSafe for ConcurrencyBudget
impl Send for ConcurrencyBudget
impl Sync for ConcurrencyBudget
impl Unpin for ConcurrencyBudget
impl UnsafeUnpin for ConcurrencyBudget
impl UnwindSafe for ConcurrencyBudget
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more