diff --git a/bb8/src/inner.rs b/bb8/src/inner.rs index 8167ba9..5dc2a23 100644 --- a/bb8/src/inner.rs +++ b/bb8/src/inner.rs @@ -29,7 +29,13 @@ where if inner.statics.max_lifetime.is_some() || inner.statics.idle_timeout.is_some() { let start = Instant::now() + inner.statics.reaper_rate; let interval = interval_at(start.into(), inner.statics.reaper_rate); - schedule_reaping(interval, Arc::downgrade(&inner)); + tokio::spawn( + Reaper { + interval, + pool: Arc::downgrade(&inner), + } + .run(), + ); } Self { inner } @@ -223,18 +229,20 @@ where } } -fn schedule_reaping(mut interval: Interval, weak_shared: Weak>) -where - M: ManageConnection, -{ - spawn(async move { +struct Reaper { + interval: Interval, + pool: Weak>, +} + +impl Reaper { + async fn run(mut self) { loop { - let _ = interval.tick().await; - if let Some(inner) = weak_shared.upgrade() { + let _ = self.interval.tick().await; + if let Some(inner) = self.pool.upgrade() { PoolInner { inner }.reap(); } else { break; } } - }); + } }