pub struct InstancePool<T, E>{ /* private fields */ }Expand description
A pool of pre-warmed instances for one plugin.
Generic over the pooled instance type T and the loader’s error
type E. Production use: InstancePool<extism::Plugin, ExtismError>
or InstancePool<wasmtime::component::Instance, WasmError>.
Implementations§
Source§impl<T, E> InstancePool<T, E>
impl<T, E> InstancePool<T, E>
Sourcepub fn new(
cfg: PoolConfig,
factory: impl Fn() -> Result<T, E> + Send + Sync + 'static,
) -> Result<Self, E>
pub fn new( cfg: PoolConfig, factory: impl Fn() -> Result<T, E> + Send + Sync + 'static, ) -> Result<Self, E>
Construct a pool that builds new instances via factory.
Eagerly constructs cfg.warm_count.min(cfg.max_instances)
instances at construction time so first-call latency is the
pool’s steady-state hit cost, not a fresh wasmtime compile.
§Errors
Propagates factory errors from initial warm-up.
Sourcepub fn acquire(&self) -> Result<T, E>
pub fn acquire(&self) -> Result<T, E>
Acquire an instance from the pool.
Pops a warm instance if available; otherwise constructs a new
one if live < max_instances. Returns a loader-specific
resource-limit error if the pool is at capacity.
§Errors
E::resource_limit(...)whenmax_instancesis reached.- Whatever the factory returns on cold-construction failure.
Sourcepub fn release(&self, inst: T)
pub fn release(&self, inst: T)
Release an instance back to the pool.
On overflow (race with reaper), the instance is dropped — its
Drop impl is responsible for any cleanup.
Sourcepub fn metrics(&self) -> Arc<PoolMetrics>
pub fn metrics(&self) -> Arc<PoolMetrics>
Snapshot the current metrics.
Sourcepub fn config(&self) -> &PoolConfig
pub fn config(&self) -> &PoolConfig
Pool configuration, for diagnostics.