Skip to main content

AsyncConnectionFactory

Trait AsyncConnectionFactory 

Source
pub trait AsyncConnectionFactory<T>: Send + Sync {
    // Required method
    fn create(&self) -> impl Future<Output = Result<T, FactoryError>> + Send;

    // Provided methods
    fn validate(&self, _conn: &T) -> impl Future<Output = bool> + Send { ... }
    fn reset(
        &self,
        _conn: &T,
    ) -> impl Future<Output = Result<(), FactoryError>> + Send { ... }
    fn close(
        &self,
        _conn: &T,
    ) -> impl Future<Output = Result<(), FactoryError>> + Send { ... }
    fn is_fatal_error(&self, _err: &(dyn Error + 'static)) -> bool { ... }
}
Expand description

Implement this to pool anything asynchronously. create must return a distinct object each call (tracked by value identity).

Required Methods§

Source

fn create(&self) -> impl Future<Output = Result<T, FactoryError>> + Send

Opens a new connection.

Provided Methods§

Source

fn validate(&self, _conn: &T) -> impl Future<Output = bool> + Send

A cheap liveness check. Defaults to true.

Source

fn reset( &self, _conn: &T, ) -> impl Future<Output = Result<(), FactoryError>> + Send

Scrubs session state on release. Defaults to a no-op.

Source

fn close( &self, _conn: &T, ) -> impl Future<Output = Result<(), FactoryError>> + Send

Disposes of a connection. Defaults to a no-op.

Source

fn is_fatal_error(&self, _err: &(dyn Error + 'static)) -> bool

Whether err proves the connection is broken. Defaults to false.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§