github
0.3版本支持tokio0.2,如果你在使用tokio0.2-alpha.6 请使用0.2版本
A generic connection pool, but async/.await
Documentation
Note: mobc requires at least Rust 1.39.
If you are using tokio 0.2-alpha.6, use mobc 0.2.11.
[dependencies]
mobc = "0.3"
use tokio;
#[tokio::main]
async fn main() {
let manager = mobc_foodb::FooConnectionManager::new("localhost:1234");
let pool = mobc::Pool::builder()
.max_size(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.
});
}
}
阅读原文:https://rust-china.org/article?id=6ce763ff-2c8a-44df-8053-3d7961806a5f