Skip to content

Commit

Permalink
change get_timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Dec 28, 2023
1 parent 24fc462 commit 519e62d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
workspace = { members = ["example"] }
[package]
name = "fast_pool"
version = "0.1.7"
version = "0.1.8"
edition = "2021"
description = "The Fast Pool based on channel"
readme = "README.md"
Expand Down
47 changes: 26 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,35 @@ impl<M: Manager> Pool<M> {
self.waits.fetch_sub(1, Ordering::SeqCst);
});
//pop connection from channel

let f = async {
let idle = self.idle_send.len() as u64;
let connections = self.in_use.load(Ordering::SeqCst) + idle;
if connections < self.max_open.load(Ordering::SeqCst) {
let conn = self.manager.connect().await?;
self.idle_send
.send(conn)
loop {
let idle = self.idle_send.len() as u64;
let connections = self.in_use.load(Ordering::SeqCst) + idle;
if connections < self.max_open.load(Ordering::SeqCst) {
//create connection
let conn = self.manager.connect().await?;
self.idle_send
.send(conn)
.map_err(|e| M::Error::from(&e.to_string()))?;
}
let mut conn = self
.idle_recv
.recv_async()
.await
.map_err(|e| M::Error::from(&e.to_string()))?;
}
let mut conn = self
.idle_recv
.recv_async()
.await
.map_err(|e| M::Error::from(&e.to_string()))?;
//check connection
match self.manager.check(&mut conn).await {
Ok(_) => Ok(conn),
Err(_e) => {
//TODO some thing need return e?
if false {
return Err(_e);
//check connection
match self.manager.check(&mut conn).await {
Ok(_) => {
break Ok(conn);
}
Err(_e) => {
//TODO some thing need return e?
if false {
return Err(_e);
}
continue;
}
conn = self.manager.connect().await?;
Ok(conn)
}
}
};
Expand Down

0 comments on commit 519e62d

Please sign in to comment.