Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Dec 18, 2020
1 parent 6ed7298 commit 2ab708c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions postgres/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,16 @@ impl Client {
self.connection.block_on(self.client.simple_query(query))
}

/// Validates connection, timing out after specified duration.
/// Validates the connection by performing a simple no-op query.
///
/// If the specified timeout is reached before the backend responds, an error will be returned.
pub fn is_valid(&mut self, timeout: Duration) -> Result<(), Error> {
let inner_client = &self.client;
self.connection.block_on(async {
let trivial_query = inner_client.simple_query("");
tokio::time::timeout(timeout, trivial_query)
.await
.map_err(|_| Error::timeout())?
.map_err(|_| Error::__private_api_timeout())?
.map(|_| ())
})
}
Expand Down
2 changes: 1 addition & 1 deletion tokio-postgres/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl Error {
}

#[doc(hidden)]
pub fn timeout() -> Error {
pub fn __private_api_timeout() -> Error {
Error::new(Kind::Timeout, None)
}
}

0 comments on commit 2ab708c

Please sign in to comment.