diff --git a/auto_pool/Cargo.toml b/auto_pool/Cargo.toml index 5168a90..f06a988 100644 --- a/auto_pool/Cargo.toml +++ b/auto_pool/Cargo.toml @@ -12,15 +12,15 @@ rust-version.workspace = true publish = true [features] -async = ["dep:async-std"] +async = ["dep:smol"] [dependencies] parking_lot = "0.12" -async-std = { version = "1.13.0", optional = true } -rand = "0.9.0" +smol = { version = "2.0", optional = true } +rand = "0.10.0" [dev-dependencies] -criterion = { version = "0.5" } +criterion = { version = "0.8" } lockfree-object-pool = "0.1.6" object-pool = "0.6.0" anyhow = "1.0" diff --git a/auto_pool/src/pool.rs b/auto_pool/src/pool.rs index f7706ac..8b81c75 100644 --- a/auto_pool/src/pool.rs +++ b/auto_pool/src/pool.rs @@ -2,7 +2,7 @@ use super::pool_object::PoolObject; use crate::config::{AutoPoolConfig, PickStrategy}; use parking_lot::lock_api::{MutexGuard, RawMutex}; use parking_lot::{Condvar, Mutex}; -use rand::RngCore; +use rand::Rng; use std::time::Duration; /// A pool of objects. @@ -49,11 +49,11 @@ impl AutoPool { } /// Take an object from the pool. - pub fn get(&self) -> Option> { self.get_with_timeout(self.config.wait_duration) } + pub fn get(&'_ self) -> Option> { self.get_with_timeout(self.config.wait_duration) } /// Async version - tries to get object, sleep if fails until timeout #[cfg(feature = "async")] - pub async fn get_async(&self) -> Option> { + pub async fn get_async(&'_ self) -> Option> { if self.config.wait_duration.is_zero() { return self.get(); } @@ -63,7 +63,7 @@ impl AutoPool { if let Some(obj) = self.get_with_timeout(self.config.lock_duration) { return Some(obj); } - async_std::task::sleep(self.config.sleep_duration).await; + smol::Timer::after(self.config.sleep_duration).await; } None } @@ -81,7 +81,7 @@ impl AutoPool { /// Shrink the pool to fit current number of items pub fn shrink_to_fit(&self) { self.storage.lock().shrink_to_fit(); } - fn get_with_timeout(&self, timeout: Duration) -> Option> { + fn get_with_timeout(&'_ self, timeout: Duration) -> Option> { let mut locked_storage = self.storage.lock(); while locked_storage.is_empty() { let wait_res = self.condvar.wait_for(&mut locked_storage, timeout); @@ -92,7 +92,7 @@ impl AutoPool { self.extract_object(locked_storage) } - fn extract_object(&self, mut locked_storage: MutexGuard>) -> Option> + fn extract_object(&'_ self, mut locked_storage: MutexGuard>) -> Option> where R: RawMutex, {