pub struct Pool<M> where
    M: Manager
{ /* private fields */ }

Implementations

Return a PoolRef contains reference of SharedManagedPool<Manager> and an Option<Manager::Connection>.

The PoolRef should be dropped asap when you finish the use of it. Hold it in scope would prevent the connection from pushed back to pool.

Return a PoolRefOwned contains a weak smart pointer of SharedManagedPool<Manager> and an Option<Manager::Connection>.

You can move PoolRefOwned to async blocks and across await point. But the performance is considerably worse than Pool::get.

Run the pool with an async closure.

example:
pool.run(|mut pool_ref| async {
    let connection = &mut *pool_ref;
    Ok(())
})

Pause the pool

these functionalities will stop:

  • get connection. Pool<Manager>::get() would eventually be timed out (If Manager::timeout is manually implemented with proper timeout function. *. Otherwise it will stuck forever in executor unless you cancel the future).
  • spawn of new connection.
  • default scheduled works (They would skip at least one iteration if the schedule time come across with the time period the pool is paused).
  • put back connection. (connection will be dropped instead.)

restart the pool.

check if the pool is running.

Clear the pool.

All pending connections will also be destroyed.

Spawned count is not reset to 0 so new connections can’t fill the pool until all outgoing PoolRef are dropped.

All PoolRef' and 'PoolRefOwned outside of pool before the clear happen would be destroyed when trying to return it’s connection to pool.

manually initialize pool. this is usually called when the Pool is built with build_uninitialized This is useful when you want to make an empty Pool and initialize it later.

example:
#[macro_use]
extern crate lazy_static;

use tokio_postgres_tang::{Pool, PostgresManager, Builder};
use tokio_postgres::NoTls;

lazy_static! {
   static ref POOL: Pool<PostgresManager<NoTls>> = Builder::new()
        .always_check(false)
        .idle_timeout(None)
        .max_lifetime(None)
        .min_idle(24)
        .max_size(24)
        .build_uninitialized(
            PostgresManager::new_from_stringlike("postgres://postgres:123@localhost/test", NoTls)
                .expect("can't make postgres manager")
        );
}

#[tokio::main]
async fn main() -> std::io::Result<()> {
    POOL.init().await.expect("Failed to initialize postgres pool");
    Ok(())
}

Change the max size of pool. This operation could result in some reallocation of PoolInner and impact the performance. (Pool<Manager>::clear() will recalibrate the pool with a capacity of current max/min pool size)

No actual check is used for new max_size. Be ware not to pass a size smaller than min_idle.

Change the min idle size of pool. (Pool<Manager>::clear() will recalibrate the pool with a capacity of current max/min pool size)

No actual check is used for new min_idle. Be ware not to pass a size bigger than max_size.

expose Manager to public

Return a state of the pool inner. This call will block the thread and wait for lock.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more