Skip to content

Commit

Permalink
Close connections from pool in serial
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfowler committed Dec 29, 2023
1 parent 41f6f4e commit 82e368d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl Client {
// If the worker thread has already shut down, return Ok here.
return Ok(());
}
// If receiving fails, the
// If receiving fails, the connection is already closed.
rx.await.unwrap_or(Ok(()))
}

Expand Down Expand Up @@ -273,6 +273,7 @@ impl Client {
if self.conn_tx.send(Command::Shutdown(func)).is_err() {
return Ok(());
}
// If receiving fails, the connection is already closed.
rx.recv().unwrap_or(Ok(()))
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,10 @@ impl Pool {
/// After this method returns, all calls to `self::conn()` or
/// `self::conn_mut()` will return an [`Error::Closed`] error.
pub async fn close(&self) -> Result<(), Error> {
let futures = self.state.clients.iter().map(|client| client.close());
join_all(futures)
.await
.into_iter()
.collect::<Result<(), Error>>()
for client in self.state.clients.iter() {
client.close().await?;
}
Ok(())
}

/// Invokes the provided function with a [`rusqlite::Connection`], blocking
Expand Down Expand Up @@ -232,7 +231,7 @@ impl Pool {
self.state
.clients
.iter()
.try_for_each(|client| client.clone().close_blocking())
.try_for_each(|client| client.close_blocking())
}

fn get(&self) -> &Client {
Expand Down

0 comments on commit 82e368d

Please sign in to comment.