pub struct Pool<M: Manager>(/* private fields */);
Expand description
A generic connection pool.
Implementations§
source§impl<M: Manager> Pool<M>
impl<M: Manager> Pool<M>
sourcepub async fn set_max_open_conns(&self, n: u64)
pub async fn set_max_open_conns(&self, n: u64)
Sets the maximum number of connections managed by the pool.
0 means unlimited, defaults to 10.
sourcepub async fn set_max_idle_conns(&self, n: u64)
pub async fn set_max_idle_conns(&self, n: u64)
Sets the maximum idle connection count maintained by the pool.
The pool will maintain at most this many idle connections
at all times, while respecting the value of max_open
.
0 means unlimited (limited only by max_open
), defaults to 2.
sourcepub async fn set_conn_max_lifetime(&self, max_lifetime: Option<Duration>)
pub async fn set_conn_max_lifetime(&self, max_lifetime: Option<Duration>)
Sets the maximum lifetime of connections in the pool.
Expired connections may be closed lazily before reuse.
None meas reuse forever. Defaults to None.
Panics
Panics if max_lifetime
is the zero Duration
.
sourcepub async fn get(&self) -> Result<Connection<M>, Error<M::Error>>
pub async fn get(&self) -> Result<Connection<M>, Error<M::Error>>
Returns a single connection by either opening a new connection or returning an existing connection from the connection pool. Conn will block until either a connection is returned or timeout.
sourcepub async fn get_timeout(
&self,
duration: Duration
) -> Result<Connection<M>, Error<M::Error>>
pub async fn get_timeout( &self, duration: Duration ) -> Result<Connection<M>, Error<M::Error>>
Retrieves a connection from the pool, waiting for at most timeout
The given timeout will be used instead of the configured connection timeout.