[][src]Trait tang_rs::Manager

pub trait Manager: Sized + Send + Sync + 'static {
    type Connection: Unpin + 'static;
    type Error: Debug + From<Self::TimeoutError> + 'static;
    type Timeout: Future<Output = Self::TimeoutError> + Send;
    type TimeoutError: Send + Debug + 'static;
    fn connect(&self) -> ManagerFuture<Result<Self::Connection, Self::Error>>;
fn is_valid<'a>(
        &'a self,
        conn: &'a mut Self::Connection
    ) -> ManagerFuture<'a, Result<(), Self::Error>>;
fn is_closed(&self, conn: &mut Self::Connection) -> bool;
fn spawn<Fut>(&self, fut: Fut)
    where
        Fut: Future<Output = ()> + Send + 'static
;
fn timeout<Fut: Future>(
        &self,
        fut: Fut,
        _dur: Duration
    ) -> ManagerTimeout<Fut, Self::Timeout>; fn on_start(&self, _shared_pool: &SharedManagedPool<Self>) { ... }
fn on_stop(&self) { ... } }

Types for different runtimes:

Trait type runtime Type constructor Manager::Timeout tokio tokio::time::Delay tokio::time::delay_for async-std smol::Timer smol::Timer::after

Manager::TimeoutError tokio () async-std std::time::Instant

Associated Types

type Connection: Unpin + 'static

type Error: Debug + From<Self::TimeoutError> + 'static

type Timeout: Future<Output = Self::TimeoutError> + Send

type TimeoutError: Send + Debug + 'static

Loading content...

Required methods

fn connect(&self) -> ManagerFuture<Result<Self::Connection, Self::Error>>

generate a new connection and put it into pool.

fn is_valid<'a>(
    &'a self,
    conn: &'a mut Self::Connection
) -> ManagerFuture<'a, Result<(), Self::Error>>

check if a connection is valid.

*. Only called when Builder.always_check == true

fn is_closed(&self, conn: &mut Self::Connection) -> bool

check if a connection is closed.

This happens before a connection put back to pool.

fn spawn<Fut>(&self, fut: Fut) where
    Fut: Future<Output = ()> + Send + 'static, 

spawn futures on your executor

The future have to be Send + 'static and the return type(e.g. JoinHandler) of your executor will be ignored.

fn timeout<Fut: Future>(
    &self,
    fut: Fut,
    _dur: Duration
) -> ManagerTimeout<Fut, Self::Timeout>

Used to cancel futures and return Manager::TimeoutError.

The duration is determined by Builder.wait_timeout and Builder.connection_timeout

Loading content...

Provided methods

fn on_start(&self, _shared_pool: &SharedManagedPool<Self>)

This method will be called when Pool<Manager>::init() executes.

fn on_stop(&self)

This method will be called when Pool<Manager> is dropping

Loading content...

Implementors

Loading content...