pub struct SharedUnboundedPool<Resource, Reset> { /* private fields */ }Expand description
A threadsafe resource pool with a growable number of Resources.
Implementations§
Sourcepub fn new(reset_resource: Reset) -> Selfwhere
Reset: ResetResource<Resource> + Clone,
pub fn new(reset_resource: Reset) -> Selfwhere
Reset: ResetResource<Resource> + Clone,
Create a new SharedUnboundedPool, which initially has zero Resources.
Whenever a Resource is returned to the pool, reset_resource is run on it first.
§Potential Panics or Deadlocks
reset_resource must not call any method on the returned pool or any Clone or
MirroredClone of it; otherwise, a panic or deadlock may occur.
Ideally, an reset_resource closure should not capture any SharedUnboundedPool.
Sourcepub fn new_without_reset() -> Self
pub fn new_without_reset() -> Self
Create a new SharedUnboundedPool, which initially has zero Resources.
When a Resource is returned to the pool, it is not reset in any way.
Sourcepub fn get_default(&self) -> PooledResource<Self, Resource>
pub fn get_default(&self) -> PooledResource<Self, Resource>
Get a Resource from the pool, returning a default Resource if none were already
available in the pool.
Sourcepub fn get<F>(&self, init_resource: F) -> PooledResource<Self, Resource>where
F: FnOnce() -> Resource,
pub fn get<F>(&self, init_resource: F) -> PooledResource<Self, Resource>where
F: FnOnce() -> Resource,
Get a Resource from the pool.
§Potential Panics or Deadlocks
init_resource must not call any method on self or a Clone or MirroredClone
associated with self; otherwise, a panic or deadlock may occur.
Ideally, an init_resource closure should not capture any SharedUnboundedPool.
Sourcepub fn pool_size(&self) -> usize
pub fn pool_size(&self) -> usize
Get the total number of Resources in this pool, whether available or in-use.
Sourcepub fn available_resources(&self) -> usize
pub fn available_resources(&self) -> usize
Get the number of Resources in the pool which are not currently being used.