A generic connection pool, but async/.await
Note: mobc requires at least Rust 1.39.
If you are using tokio 0.2-alpha.6, use mobc 0.2.10.
toml
[dependencies]
mobc = "0.3.0"
```rust use tokio;
async fn main() { let manager = mobcfoodb::FooConnectionManager::new("localhost:1234"); let pool = mobc::Pool::builder() .maxsize(15) .build(manager) .await .unwrap();
for _ in 0..20 {
let pool = pool.clone();
tokio::spawn(async {
let conn = pool.get().await.unwrap();
// use the connection
// it will be returned to the pool when it falls out of scope.
});
}
}
```