After connection is drop()
ed, it becomes parmanently unable to use
#279
-
I am using Let's say I have connections in deadpool. let pool: Pool<AsyncPgConnection> = Pool::builder(deadpool_config)
.max_size(2) // <== max size is 2
.build()
.unwrap();
// share the pool with async thread
let _pool = pool.clone();
tokio::spawn(async move {
for i in 0..3 {
let mut conn = _pool.get().await.unwrap();
// This works when i == 0 or i == 1, but not when i == 2
do_something(&mut conn);
}
}); So it seems like I just want the connection when I need, and then return it back to the pool after use. I hoped Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I'm wondering about that comment: // This works when i == 0 or i == 1, but not when i == 2 The for loop |
Beta Was this translation helpful? Give feedback.
I'm wondering about that comment:
// This works when i == 0 or i == 1, but not when i == 2
The for loop
for i in 0..2 { ... }
will only iterate over0
and1
. If you meant to write a loop that goes from0
to2
(inclusive) you can usefor i in 0..=2 {...}
instead.