[][src]Trait roa_diesel::preload::AsyncPool

pub trait AsyncPool<Conn> where
    Conn: Connection + 'static, 
{ #[must_use] fn get_conn<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = Result<WrapConnection<Conn>, Status>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
;
#[must_use] fn get_timeout<'life0, 'async_trait>(
        &'life0 self,
        timeout: Duration
    ) -> Pin<Box<dyn Future<Output = Result<WrapConnection<Conn>, Status>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
;
#[must_use] fn pool_state<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = State> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
; }

A context extension to access r2d2 pool asynchronously.

Required methods

#[must_use]fn get_conn<'life0, 'async_trait>(
    &'life0 self
) -> Pin<Box<dyn Future<Output = Result<WrapConnection<Conn>, Status>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    Self: 'async_trait, 

Retrieves a connection from the pool.

Waits for at most the configured connection timeout before returning an error.

use roa::{Context, Result};
use diesel::sqlite::SqliteConnection;
use roa_diesel::preload::AsyncPool;
use roa_diesel::Pool;
use diesel::r2d2::ConnectionManager;

#[derive(Clone)]
struct State(Pool<SqliteConnection>);

impl AsRef<Pool<SqliteConnection>> for State {
    fn as_ref(&self) -> &Pool<SqliteConnection> {
        &self.0
    }
}

async fn get(ctx: Context<State>) -> Result {
    let conn = ctx.get_conn().await?;
    // handle conn
    Ok(())
}

#[must_use]fn get_timeout<'life0, 'async_trait>(
    &'life0 self,
    timeout: Duration
) -> Pin<Box<dyn Future<Output = Result<WrapConnection<Conn>, Status>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    Self: 'async_trait, 

Retrieves a connection from the pool, waiting for at most timeout

The given timeout will be used instead of the configured connection timeout.

#[must_use]fn pool_state<'life0, 'async_trait>(
    &'life0 self
) -> Pin<Box<dyn Future<Output = State> + Send + 'async_trait>> where
    'life0: 'async_trait,
    Self: 'async_trait, 

Returns information about the current state of the pool.

Loading content...

Implementations on Foreign Types

impl<S, Conn> AsyncPool<Conn> for Context<S> where
    S: State + AsRef<Pool<Conn>>,
    Conn: Connection + 'static, 
[src]

Loading content...

Implementors

Loading content...