A generic resource pool for the Tokio ecosystem.

Example

To use it, you need to implment Manage for your resource, and then create a Pool with its background worker, spawn the worker. Once this is done, you can request a resource by calling Pool::check_out.

```rust use futures::future::{lazy, Future, FutureResult, IntoFuture}; use redis::{RedisError, RedisResult}; use tokio;

use tokioresourcepool::{Manage, Pool};

struct RedisConnectionManager { client: redis::Client, }

impl RedisConnectionManager { fn new(url: impl redis::IntoConnectionInfo) -> RedisResult { let client = redis::Client::open(url)?; Ok(Self { client }) } }

impl Manage for RedisConnectionManager { type Resource = redis::Connection;

type Error = RedisError;

type Future = FutureResult<Self::Resource, Self::Error>;

fn create(&self) -> Self::Future {
    self.client.get_connection().into_future()
}

}

let manager = RedisConnectionManager::new("redis://127.0.0.1/")?; tokio::run(lazy(move || { let (pool, librarian) = Pool::new(4, manager); tokio::spawn(librarian); tokio::spawn( pool.checkout() .andthen(|connection| { redis::cmd("INFO").query::(&*connection) }) .map(|info| println!("{:#?}", info)) .map_err(|error| eprintln!("error: {}", error)), ) })); ```

Alternatives

There is another resource pool called bb8. It has two significant differences.