pub struct InstancePool<T, E>{ /* private fields */ }Expand description
A per-plugin instance cache with a concurrency cap.
Generic over the per-invoke instance type T and the loader’s error
type E. Production use: InstancePool<extism::Plugin, ExtismError>
or InstancePool<ScalarPluginInstance, WasmError>.
Does not reuse instances — every Self::acquire builds a fresh
one and every release drops it. See the module docs for why.
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 fresh instances via factory.
cfg.warm_count is accepted for API compatibility but ignored:
nothing is pre-warmed, because instances are never reused.
§Errors
This constructor is infallible in practice; the E in the return
type is retained so the signature is stable across the refactor.
Sourcepub fn acquire(&self) -> Result<T, E>
pub fn acquire(&self) -> Result<T, E>
Acquire a fresh instance, honoring the concurrency cap.
Reserves a live slot (CAS against max_instances), then builds a
brand-new instance via the factory. No warm reuse — the returned
instance has clean state. Releasing it (via PooledInstance’s
drop) frees the slot.
§Errors
E::resource_limit(...)whenmax_instancesis reached.- Whatever the factory returns on construction failure.
Sourcepub fn release(&self, inst: T)
pub fn release(&self, inst: T)
Release an instance, freeing its concurrency slot.
The instance is dropped here (never recycled), so its Drop impl
runs any cleanup. A trapped instance is therefore discarded, not
handed back out.
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.