pub struct ResourcePool<T> { /* private fields */ }Expand description
A resource pool that manages the lifecycle of expensive resources
This pool provides thread-safe access to resources with automatic cleanup, health checking, and graceful degradation.
Implementations§
Source§impl<T> ResourcePool<T>where
T: Send + 'static,
impl<T> ResourcePool<T>where
T: Send + 'static,
Sourcepub fn new<F>(
config: PoolConfig,
factory: F,
) -> Result<Self, Box<dyn Error + Send + Sync>>
pub fn new<F>( config: PoolConfig, factory: F, ) -> Result<Self, Box<dyn Error + Send + Sync>>
Sourcepub fn with_health_checker<F>(self, health_checker: F) -> Self
pub fn with_health_checker<F>(self, health_checker: F) -> Self
Set a health checker function for resources
The health checker is called periodically to validate that pooled resources are still healthy.
Sourcepub fn acquire(&self) -> Result<ResourceGuard<T>, Box<dyn Error + Send + Sync>>
pub fn acquire(&self) -> Result<ResourceGuard<T>, Box<dyn Error + Send + Sync>>
Acquire a resource from the pool
This method will either return an existing resource from the pool or create a new one if the pool is not at capacity.
§Returns
A ResourceGuard that automatically returns the resource to the pool
when dropped.
Auto Trait Implementations§
impl<T> Freeze for ResourcePool<T>
impl<T> !RefUnwindSafe for ResourcePool<T>
impl<T> Send for ResourcePool<T>where
T: Send,
impl<T> Sync for ResourcePool<T>where
T: Send,
impl<T> Unpin for ResourcePool<T>
impl<T> UnsafeUnpin for ResourcePool<T>
impl<T> !UnwindSafe for ResourcePool<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more