pub struct ConnectionPool<S> { /* private fields */ }
Expand description
Connection pool
ConnectionPool holds reusable connections. A reusable connection is released to this pool to be picked up by another user/request.
Implementations§
Source§impl<S> ConnectionPool<S>
impl<S> ConnectionPool<S>
Sourcepub fn new(size: usize) -> Self
pub fn new(size: usize) -> Self
Create a new ConnectionPool with a size limit.
When a connection is released to this pool, the least recently used connection will be dropped.
pub fn pop_closed(&self, meta: &ConnectionMeta)
Sourcepub fn get(&self, key: &u64) -> Option<S>
pub fn get(&self, key: &u64) -> Option<S>
Get a connection from this pool under the same group key
Sourcepub fn put(
&self,
meta: &ConnectionMeta,
connection: S,
) -> (Arc<Notify>, Receiver<bool>)
pub fn put( &self, meta: &ConnectionMeta, connection: S, ) -> (Arc<Notify>, Receiver<bool>)
Release a connection to this pool for reuse
- The returned
Arc<Notify>
will notify any listen when the connection is evicted from the pool. - The returned
oneshot::Receiver<bool>
will notify when the connection is being picked up by Self::get().
Sourcepub async fn idle_poll<Stream>(
&self,
connection: OwnedMutexGuard<Stream>,
meta: &ConnectionMeta,
timeout: Option<Duration>,
notify_evicted: Arc<Notify>,
watch_use: Receiver<bool>,
)
pub async fn idle_poll<Stream>( &self, connection: OwnedMutexGuard<Stream>, meta: &ConnectionMeta, timeout: Option<Duration>, notify_evicted: Arc<Notify>, watch_use: Receiver<bool>, )
Actively monitor the health of a connection that is already released to this pool
When the connection breaks, or the optional timeout
is reached this function will
remove it from the pool and drop the connection.
If the connection is reused via Self::get() or being evicted, this function will just exit.
Sourcepub async fn idle_timeout(
&self,
meta: &ConnectionMeta,
timeout: Duration,
notify_evicted: Arc<Notify>,
notify_closed: Receiver<bool>,
watch_use: Receiver<bool>,
)
pub async fn idle_timeout( &self, meta: &ConnectionMeta, timeout: Duration, notify_evicted: Arc<Notify>, notify_closed: Receiver<bool>, watch_use: Receiver<bool>, )
Passively wait to close the connection after the timeout
If this connection is not being picked up or evicted before the timeout is reach, this function will remove it from the pool and close the connection.