Skip to content

Commit

Permalink
Inline make_pooled() into get()
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Jan 28, 2024
1 parent a3ae57c commit ba97724
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions bb8/src/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,36 @@ where
}

pub(crate) async fn get(&self) -> Result<PooledConnection<'_, M>, RunError<M::Error>> {
let future = self.make_pooled(PooledConnection::new);
match timeout(self.inner.statics.connection_timeout, future).await {
Ok(result) => result,
_ => Err(RunError::TimedOut),
}
}
let future = async {
loop {
let (conn, approvals) = self.inner.pop();
self.spawn_replenishing_approvals(approvals);
let mut conn = match conn {
Some(conn) => PooledConnection::new(self, conn),
None => {
self.inner.notify.notified().await;
continue;
}
};

pub(crate) async fn make_pooled<'a, 'b>(
&'a self,
make_pooled_conn: impl Fn(&'a Self, Conn<M::Connection>) -> PooledConnection<'b, M>,
) -> Result<PooledConnection<'b, M>, RunError<M::Error>> {
loop {
let (conn, approvals) = self.inner.pop();
self.spawn_replenishing_approvals(approvals);
let mut conn = match conn {
Some(conn) => make_pooled_conn(self, conn),
None => {
self.inner.notify.notified().await;
continue;
if !self.inner.statics.test_on_check_out {
return Ok(conn);
}
};

if !self.inner.statics.test_on_check_out {
return Ok(conn);
}

match self.inner.manager.is_valid(&mut conn).await {
Ok(()) => return Ok(conn),
Err(e) => {
self.inner.forward_error(e);
conn.drop_invalid();
continue;
match self.inner.manager.is_valid(&mut conn).await {
Ok(()) => return Ok(conn),
Err(e) => {
self.inner.forward_error(e);
conn.drop_invalid();
continue;
}
}
}
};

match timeout(self.inner.statics.connection_timeout, future).await {
Ok(result) => result,
_ => Err(RunError::TimedOut),
}
}

Expand Down

0 comments on commit ba97724

Please sign in to comment.