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>
impl<const N: usize> WorkerPool<N>
Sourcepub fn new(
name_prefix: &'static str,
roster: [WorkerRole; N],
capacity: usize,
) -> Self
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.
Sourcepub fn acquire(&self) -> Result<(SetLease, [Worker; N]), AcquireError>
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 (Nthreads); - none, and at capacity →
AcquireError::AtCapacitycarrying the bound that was reached; - a thread could not be created →
AcquireError::SpawnFailed, withcreatedleft 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.
Sourcepub fn worker_count(&self) -> usize
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.