Skip to main content

WorkerPool

Struct WorkerPool 

Source
pub struct WorkerPool<const N: usize> { /* private fields */ }
Expand description

A bounded, per-role set of persistent threads that connections borrow.

N is the set size — three for the PVA server (conn, reader, writer), two for a blocking client’s circuit (reader, writer). Worker and SetLease are not generic over N, so a leased worker crosses into the byte-pump seam without spreading a const parameter through every signature.

Implementations§

Source§

impl<const N: usize> WorkerPool<N>

Source

pub fn new( name_prefix: &'static str, roster: [WorkerRole; N], capacity: usize, ) -> Self

Declare a role’s pool. Lazy: no thread exists until the first acquire that cannot reuse an idle set.

capacity is the most sets that may ever exist, and for a server it is the connection limit — admission refuses past it. Not const, because a pool owns heap state; a process-lifetime pool is a LazyLock<WorkerPool>, a server-lifetime pool is a field dropped with the server.

Source

pub fn acquire(&self) -> Result<(SetLease, [Worker; N]), AcquireError>

Borrow a whole set, or refuse.

  • an idle set exists → reuse it (no thread created);
  • none, and created < capacity → grow by one set (N threads);
  • none, and at capacity → AcquireError::AtCapacity carrying the bound that was reached;
  • a thread could not be created → AcquireError::SpawnFailed, with created left exactly as it was found.

The refusals are a sum type and not an io::Error because they mean opposite things — a full process versus a target out of thread resources — and as io::Error they were indistinguishable: both are ErrorKind::WouldBlock. See AcquireError.

Source

pub fn worker_count(&self) -> usize

Threads this pool has created, ever — never more than capacity × N. The bound made observable: the number the per-connection shape grew without limit.

Source

pub fn set_usage(&self) -> (usize, usize, usize)

(busy_sets, created_sets, capacity) — the admission state.

Deliberately not queue_depth: there is no queue, admission refuses, and a name that promised one would be the dual meaning this design removes.

Trait Implementations§

Source§

impl<const N: usize> Drop for WorkerPool<N>

Source§

fn drop(&mut self)

Retire every worker thread. A process-lifetime pool (a static LazyLock) never reaches here; a server-lifetime pool does, at server drop, and must be dropped after the server’s connections have been asked to stop, so the Stops do not queue behind a live connection forever.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for WorkerPool<N>

§

impl<const N: usize> RefUnwindSafe for WorkerPool<N>

§

impl<const N: usize> Send for WorkerPool<N>

§

impl<const N: usize> Sync for WorkerPool<N>

§

impl<const N: usize> Unpin for WorkerPool<N>

§

impl<const N: usize> UnsafeUnpin for WorkerPool<N>

§

impl<const N: usize> UnwindSafe for WorkerPool<N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more