Whitepool is a lightweight, generic pooling library for Rust+Tokio inspired by Elixir poolboy

Whitepool - A hunky Rust+Tokio worker pool factory

  • WhitePool is a lightweight, generic pooling library for Rust+Tokio
    with a focus on simplicity, performance, and rock-solid disaster recovery.

  • Whitepool inspired by Elixir/Erlang Poolboy
    almost all Elixir/Erlang Database library rely on it for Connetcion Pooling


async fn main() {

    let pool_size = 7;
    let max_overflow = 4;

    // Create a session for communicate with pool channel
    let session = Pool::new(pool_size, 
                            || {Box::pin(async move {

                                // tokio_postgres create connection 

                                let (client, connection) =
                                        tokio_postgres::connect("host=localhost user=postgres", NoTls)

                                tokio::spawn(async move {
                                    if let Err(e) = connection.await {
                                        eprintln!("connection error: {}", e);
                                // return client


    // session.clone() internally call channel mpsc::Sender::Clone

    // wait until all pending checkout handled, then shutdown


pub async fn process(session: Session<Client>) {

    // Checkout a resource from Pool
    // block_checkout don't block your scheduler
    // just await on oneshot with timeout
    if let Ok(mut client) = session.block_checkout().await {
    // ============== start ===================

        let _rows = client
                    .query("SELECT $1::TEXT", &[&"hello world"])

    // ============== end ===================

        // after job done, call checkin
        let _ = session.checkin(client).await;

        // OR if resource destroy, call this
        // session.destroyed(client).await;


  • pool_size: maximum pool size
  • max_overflow: maximum number of workers created if pool is empty
  • factory: is a closure create a worker



whitepool = "1.0.0"

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.