pub struct ReadPool { /* private fields */ }Expand description
A bounded pool of reader connections. Clones share one pool.
Implementations§
Source§impl ReadPool
impl ReadPool
Sourcepub fn from_opener(
cap: usize,
open: impl Fn() -> Result<Connection> + Send + Sync + 'static,
) -> Result<Self>
pub fn from_opener( cap: usize, open: impl Fn() -> Result<Connection> + Send + Sync + 'static, ) -> Result<Self>
A pool whose readers come from open, called once now to check it works and again for
each new reader. The pool enforces cap and the closed and wait rules; query_only and
other reader setup are the opener’s job. Intended for tests that need a pool over a
connection they build themselves. Use DbOptions::open_read_pool for a real database.
Sourcepub fn get(&self) -> Result<PooledReadConnection>
pub fn get(&self) -> Result<PooledReadConnection>
Checks out an idle reader, opens a new one while under the cap, or waits for a return.
Fails with DbError::ReadPoolClosed once the pool is closed, including while waiting.
The wait has no bound; use Self::get_timeout to give up after a deadline.
Sourcepub fn get_timeout(
&self,
timeout: Duration,
) -> Result<Option<PooledReadConnection>>
pub fn get_timeout( &self, timeout: Duration, ) -> Result<Option<PooledReadConnection>>
Self::get with a bounded wait. Returns Ok(Some(reader)) as soon as a reader is idle
or can be opened under the cap, and Ok(None) if none frees up within timeout. A zero
timeout never waits: it returns an idle or newly opened reader, or Ok(None). If the
pool is closed, or closes while waiting, the result is DbError::ReadPoolClosed, never
Ok(None). Opening a new reader is not bounded by timeout. A timeout too large for the
clock waits in bounded slices until a reader frees up or the pool closes.
Sourcepub fn close(&self)
pub fn close(&self)
Stops handing out readers and drops the idle ones now. A reader still checked out closes when it is returned. Calling it again does nothing.
Sourcepub fn close_and_wait(&self, timeout: Duration) -> Result<()>
pub fn close_and_wait(&self, timeout: Duration) -> Result<()>
Self::close, then waits up to timeout for every checked-out reader to be returned.
Ok(()) means every connection is closed and its database file released. Otherwise it
returns DbError::ReadPoolCloseTimeout with the number still out. Do not call it while
holding a reader from this pool: that reader cannot come back, so the call times out. A
timeout too large for the clock waits in bounded slices until the readers return.