pub struct AsyncPromotionPool { /* private fields */ }Expand description
Bounded, drop-oldest async promotion pool.
See module docs for design rationale.
Implementations§
Source§impl AsyncPromotionPool
impl AsyncPromotionPool
Sourcepub fn new(opts: PoolOpts) -> Arc<AsyncPromotionPool> ⓘ
pub fn new(opts: PoolOpts) -> Arc<AsyncPromotionPool> ⓘ
Construct a pool with a no-op executor. Useful only for tests / dry runs where you want metrics but no actual promotion side-effects.
Sourcepub fn new_with_executor(
opts: PoolOpts,
executor: Arc<dyn Fn(PromotionRequest) -> Result<(), String> + Send + Sync>,
) -> Arc<AsyncPromotionPool> ⓘ
pub fn new_with_executor( opts: PoolOpts, executor: Arc<dyn Fn(PromotionRequest) -> Result<(), String> + Send + Sync>, ) -> Arc<AsyncPromotionPool> ⓘ
Construct a pool with a caller-provided executor closure.
Spawns opts.worker_count tokio tasks that drain the queue. Each
task holds a Weak<Self> so the pool is dropped cleanly once the
caller releases its Arc and the workers exit.
Sourcepub fn schedule(&self, request: PromotionRequest) -> ScheduleOutcome
pub fn schedule(&self, request: PromotionRequest) -> ScheduleOutcome
Hand a promotion request to the pool.
Never blocks. If the queue has capacity, the request is enqueued and
Queued is returned. If the queue is full, the oldest request is
popped (and dropped) to make room — the caller learns this via
DroppedQueueFull { evicted_oldest: true }. In the rare case where
the queue is so contended that even the pop fails, the new
request is dropped: DroppedQueueFull { evicted_oldest: false }.
Sourcepub fn shutdown(self: Arc<AsyncPromotionPool>)
pub fn shutdown(self: Arc<AsyncPromotionPool>)
Signal workers to drain remaining work and exit.
Workers will process at most drain_budget more requests after the
shutdown flag is observed, then return. New schedule calls after
shutdown are rejected (counted in dropped_total).
Sourcepub fn metrics(&self) -> PromotionMetrics
pub fn metrics(&self) -> PromotionMetrics
Snapshot of the pool’s atomic counters.
Each counter is read with Relaxed ordering; the snapshot is not
strictly atomic across counters (it can show, e.g., one more
queued_total than the queue depth implies if a worker is mid-pop).
This is acceptable for monitoring; consumers that need a strictly
consistent view should sample twice and take the difference.
Auto Trait Implementations§
impl !Freeze for AsyncPromotionPool
impl !RefUnwindSafe for AsyncPromotionPool
impl Send for AsyncPromotionPool
impl Sync for AsyncPromotionPool
impl Unpin for AsyncPromotionPool
impl UnsafeUnpin for AsyncPromotionPool
impl !UnwindSafe for AsyncPromotionPool
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
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>
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>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request