pub struct AsyncPool { /* private fields */ }Expand description
An async facade over a Pool.
with is the primitive: it checks a connection out of the
pool and runs a closure against it on a blocking thread, releasing the
checkout when the closure returns. This is deliberately the only way to touch
a pooled connection — holding a long-lived pooled-connection guard across
.await points is the classic way to deadlock an async pool, since it pins a
pool slot for the entire suspension.
Implementations§
Source§impl AsyncPool
impl AsyncPool
Sourcepub async fn state(&self) -> PoolState
pub async fn state(&self) -> PoolState
Returns the pool’s current idle/active connection counts.
Sourcepub async fn with<F, T>(&self, f: F) -> Result<T>
pub async fn with<F, T>(&self, f: F) -> Result<T>
Checks a connection out of the pool and runs f against it on a blocking
thread. The checkout is released when f returns.
This is the correct place to run a transaction: a transaction must not
span an .await point.
§Errors
Returns an error if checkout times out, or if the closure returns one.
Sourcepub async fn execute_batch<S>(&self, sql: S) -> Result<()>
pub async fn execute_batch<S>(&self, sql: S) -> Result<()>
Executes one or more SQL statements separated by semicolons on a pooled connection.
§Errors
Returns an error if checkout times out or any statement fails to execute.
Sourcepub async fn execute<S>(&self, sql: S) -> Result<ResultSet>
pub async fn execute<S>(&self, sql: S) -> Result<ResultSet>
Prepares and executes a SQL statement on a pooled connection, materializing the result.
§Errors
Returns an error if checkout times out or the statement fails.