Why example use `let pool = pool.clone()` in a for loop ?
linrongbin16 opened this issue · 2 comments
linrongbin16 commented
I want to use r2d2 with diesel for connecting mysql and sqlite3.
In example code:
use std::thread;
extern crate r2d2;
extern crate r2d2_foodb;
fn main() {
let manager = r2d2_foodb::FooConnectionManager::new("localhost:1234");
let pool = r2d2::Pool::builder()
.max_size(15)
.build(manager)
.unwrap();
for _ in 0..20 {
let pool = pool.clone();
thread::spawn(move || {
let conn = pool.get().unwrap();
// use the connection
// it will be returned to the pool when it falls out of scope.
})
}
}
I don't get the meaning of the pool.clone
, can I simply remove this line ?
sfackler commented
What happens when you try to remove the line?
linrongbin16 commented
Hi, I got the answer here: https://stackoverflow.com/questions/66400432/why-is-the-connection-pool-cloned-here.