Skip to content

Commit ef77eab

Browse files
committed
fix some error
1 parent f52fedb commit ef77eab

4 files changed

Lines changed: 35 additions & 9 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
/.vscode
1414
'.vscode'
1515
/.github
16+
.claude/
17+
1618

1719

1820

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
workspace = { members = ["example"] }
22
[package]
33
name = "fast_pool"
4-
version = "1.0.0"
4+
version = "1.0.1"
55
edition = "2021"
66
description = "The Fast Pool based on channel"
77
readme = "README.md"

src/plugin/duration_manager.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl CheckModeAtomic {
8787
/// Connection wrapper with creation timestamp for lifetime tracking
8888
pub struct DurationConnection<T> {
8989
inner: T,
90-
instant: Instant,
90+
instant: Option<Instant>,
9191
}
9292

9393
impl<T> Deref for DurationConnection<T> {
@@ -156,7 +156,13 @@ impl<M: Manager> Manager for DurationManager<M> {
156156
async fn connect(&self) -> Result<Self::Connection, Self::Error> {
157157
Ok(DurationConnection {
158158
inner: self.manager.connect().await?,
159-
instant: Instant::now(),
159+
instant: {
160+
match self.mode.get_mode() {
161+
CheckMode::NoLimit => None,
162+
CheckMode::SkipInterval(_) => Some(Instant::now()),
163+
CheckMode::MaxLifetime(_) => Some(Instant::now()),
164+
}
165+
},
160166
})
161167
}
162168

@@ -168,17 +174,35 @@ impl<M: Manager> Manager for DurationManager<M> {
168174
}
169175
CheckMode::SkipInterval(duration) => {
170176
// Skip if within check interval
171-
if conn.instant.elapsed() < *duration {
172-
return Ok(());
177+
if let Some(instant) = conn.instant.as_ref() {
178+
if instant.elapsed() < *duration {
179+
return Ok(());
180+
}
173181
}
174182
}
175-
CheckMode::MaxLifetime(max_lifetime) => {
183+
CheckMode::MaxLifetime(duration) => {
176184
// Fail if connection exceeded max lifetime
177-
if conn.instant.elapsed() > *max_lifetime {
178-
return Err(M::Error::from("connection exceeded max lifetime"));
185+
if let Some(instant) = conn.instant.as_ref() {
186+
if instant.elapsed() > *duration {
187+
return Err(M::Error::from("connection exceeded max lifetime"));
188+
}
179189
}
180190
}
181191
}
182192
self.manager.check(conn).await
183193
}
184194
}
195+
196+
197+
impl<M: Manager> Deref for DurationManager<M> {
198+
type Target = M;
199+
fn deref(&self) -> &Self::Target {
200+
&self.manager
201+
}
202+
}
203+
204+
impl<M: Manager> DerefMut for DurationManager<M> {
205+
fn deref_mut(&mut self) -> &mut Self::Target {
206+
&mut self.manager
207+
}
208+
}

tests/pool_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,6 @@ async fn test_downcast() {
719719
async fn test_downcast2() {
720720
let p = Pool::new(DurationManager::new(TestManager {}, CheckMode::NoLimit));
721721
p.set_max_open(1);
722-
let manager = p.downcast_manager::<TestManager>().unwrap();
722+
let manager = p.downcast_manager::<DurationManager<TestManager>>().unwrap();
723723
manager.hello();
724724
}

0 commit comments

Comments
 (0)