pub struct SharedBoundedPool<Resource, Reset> { /* private fields */ }Expand description
A threadsafe resource pool with a fixed number of Resources.
Implementations§
Sourcepub fn new<F>(pool_size: usize, init_resource: F, reset_resource: Reset) -> Self
pub fn new<F>(pool_size: usize, init_resource: F, reset_resource: Reset) -> Self
Create a new SharedBoundedPool which has the indicated, fixed number of Resources.
Each Resource is immediately initialized, using the provided function.
Whenever a Resource is returned to the pool, reset_resource is run on it first.
Sourcepub fn new_default(pool_size: usize, reset_resource: Reset) -> Selfwhere
Reset: ResetResource<Resource> + Clone,
pub fn new_default(pool_size: usize, reset_resource: Reset) -> Selfwhere
Reset: ResetResource<Resource> + Clone,
Create a new SharedBoundedPool which has the indicated, fixed number of Resources.
Each Resource is immediately initialized to its default value.
Whenever a Resource is returned to the pool, reset_resource is run on it first.
Sourcepub fn new_without_reset<F>(pool_size: usize, init_resource: F) -> Selfwhere
F: FnMut() -> Resource,
pub fn new_without_reset<F>(pool_size: usize, init_resource: F) -> Selfwhere
F: FnMut() -> Resource,
Create a new SharedBoundedPool which has the indicated, fixed number of Resources.
Each Resource is immediately initialized, using the provided function.
When a Resource is returned to the pool, it is not reset in any way.
Sourcepub fn new_default_without_reset(pool_size: usize) -> Self
pub fn new_default_without_reset(pool_size: usize) -> Self
Create a new SharedBoundedPool which has the indicated, fixed number of Resources.
Each Resource is immediately initialized to its default value.
When a Resource is returned to the pool, it is not reset in any way.
Sourcepub fn try_get(
&self,
) -> Result<PooledResource<Self, Resource>, ResourcePoolEmpty>
pub fn try_get( &self, ) -> Result<PooledResource<Self, Resource>, ResourcePoolEmpty>
Get a Resource from the pool, if any are available.
Sourcepub fn get(&self) -> PooledResource<Self, Resource>
pub fn get(&self) -> PooledResource<Self, Resource>
Get a Resource from the pool.
May need to wait for a resource to become available.
§Potential Panics or Deadlocks
If self.pool_size() == 0, then this method will panic or deadlock.
This method may also cause a deadlock if no Resources are currently available, and the
current thread needs to make progress in order to release a Resource.
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.