From 2be4601150cde50681155b6799df16738bab877d Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 24 Sep 2020 20:28:51 -0400 Subject: [PATCH] Add `size()` and `num_idle()` --- sqlx-core/src/pool/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sqlx-core/src/pool/mod.rs b/sqlx-core/src/pool/mod.rs index a5b8b468..1458dd13 100644 --- a/sqlx-core/src/pool/mod.rs +++ b/sqlx-core/src/pool/mod.rs @@ -145,6 +145,20 @@ impl Pool { pub fn is_closed(&self) -> bool { self.0.is_closed() } + + /// Returns the number of connections currently active. This includes idle connections. + pub fn size(&self) -> u32 { + self.0.size() + } + + /// Returns the number of connections active and idle (not in use). + /// + /// This will block until the number of connections stops changing for at + /// least 2 atomic accesses in a row. If the number of idle connections is + /// changing rapidly, this may run indefinitely. + pub fn num_idle(&self) -> usize { + self.0.num_idle() + } } /// Returns a new [Pool] tied to the same shared connection pool.