[−][src]Struct tang_rs::Pool
Implementations
impl<M: Manager> Pool<M>
[src]
#[must_use = "futures do nothing unless you `.await` or poll them"]pub async fn get<'_, '_>(&'_ self) -> Result<PoolRef<'_, M>, M::Error>
[src]
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.
#[must_use = "futures do nothing unless you `.await` or poll them"]pub async fn get_owned<'_>(&'_ self) -> Result<PoolRefOwned<M>, M::Error>
[src]
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
.
#[must_use = "futures do nothing unless you `.await` or poll them"]pub async fn run<'a, T, E, F, FF>(&'a self, f: F) -> Result<T, E> where
F: FnOnce(PoolRef<'a, M>) -> FF,
FF: Future<Output = Result<T, E>> + Send + 'a,
E: From<M::Error>,
T: Send + 'static,
[src]
F: FnOnce(PoolRef<'a, M>) -> FF,
FF: Future<Output = Result<T, E>> + Send + 'a,
E: From<M::Error>,
T: Send + 'static,
Run the pool with an async closure.
example:
pool.run(|mut pool_ref| async { let connection = &mut *pool_ref; Ok(()) })
pub fn pause(&self)
[src]
Pause the pool
these functionalities will stop:
- get connection.
Pool<Manager>::get()
would eventually be timed out (IfManager::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.)
pub fn resume(&self)
[src]
restart the pool.
pub fn running(&self) -> bool
[src]
check if the pool is running.
pub fn clear(&self)
[src]
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.
#[must_use = "futures do nothing unless you `.await` or poll them"]pub async fn init<'_>(&'_ self) -> Result<(), M::Error>
[src]
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(()) }
pub fn set_max_size(&self, size: usize)
[src]
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
.
pub fn set_min_idle(&self, size: usize)
[src]
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
.
pub fn get_manager(&self) -> &M
[src]
expose Manager
to public
pub fn state(&self) -> State
[src]
Return a state of the pool inner. This call will block the thread and wait for lock.
Trait Implementations
impl<M: Manager> Clone for Pool<M>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<M: Manager> Debug for Pool<M>
[src]
impl<M: Manager> Drop for Pool<M>
[src]
Auto Trait Implementations
impl<M> !RefUnwindSafe for Pool<M>
impl<M> Send for Pool<M>
impl<M> Sync for Pool<M>
impl<M> Unpin for Pool<M>
impl<M> !UnwindSafe for Pool<M>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,