pub struct Pool { /* private fields */ }Expand description
An elastic pool of monty subprocess workers.
min_processes workers spawn eagerly so the first checkout is fast;
further workers spawn on demand up to max_processes, and dead workers
are detected and replaced transparently. See the crate docs for the full
lifecycle.
Pool is safe to share across tasks and threads. Pool::close asks idle
workers to exit cleanly; merely dropping the pool kills them instead (via
their kill-on-drop handles). Workers held by live Checkouts die when
those are finished or dropped.
Implementations§
Source§impl Pool
impl Pool
Sourcepub async fn new(config: PoolConfig) -> Result<Self, PoolError>
pub async fn new(config: PoolConfig) -> Result<Self, PoolError>
Creates the pool and eagerly spawns min_processes workers, failing
fast if the binary cannot be spawned. Must be called within a tokio
runtime (worker process and pipe I/O is driven by the runtime).
Sourcepub async fn checkout(&self, repl: &ReplConfig) -> Result<Checkout, PoolError>
pub async fn checkout(&self, repl: &ReplConfig) -> Result<Checkout, PoolError>
Dedicates a worker to one REPL session created from repl, with
default CheckoutOptions — see Self::checkout_with.
Sourcepub async fn checkout_with(
&self,
repl: &ReplConfig,
options: CheckoutOptions,
) -> Result<Checkout, PoolError>
pub async fn checkout_with( &self, repl: &ReplConfig, options: CheckoutOptions, ) -> Result<Checkout, PoolError>
Dedicates a worker to one REPL session created from repl, with the
host context options carries.
Takes an idle worker when one exists, spawns or dials a new one (with
options.connect_headers, preceded by the W3C trace headers of
options.telemetry) while below max_processes, and otherwise waits
up to checkout_timeout (forever when None) before failing with
PoolError::Exhausted.
Sourcepub async fn close(&self)
pub async fn close(&self)
Asks idle workers to exit cleanly and reaps them, capping the wait per worker. Sessions still checked out keep their workers until they finish.
Optional: dropping the pool kills idle workers instead, which is just as safe — this only trades a SIGKILL for a clean protocol goodbye.
Telemetry exporter shutdown remains the configuring application’s responsibility and should happen after checked-out sessions finish.
Sourcepub fn idle_workers(&self) -> usize
pub fn idle_workers(&self) -> usize
Number of idle workers right now (diagnostics/tests only — the value is stale the moment it is returned).
Sourcepub fn idle_worker_pids(&self) -> Vec<u32>
pub fn idle_worker_pids(&self) -> Vec<u32>
PIDs of the idle workers (diagnostics/tests only).