-
-
Notifications
You must be signed in to change notification settings - Fork 487
Support connection validation with timeout #711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
tokio-postgres/src/client.rs
Outdated
@@ -450,6 +450,15 @@ impl Client { | |||
self.simple_query_raw(query).await?.try_collect().await | |||
} | |||
|
|||
/// Validates connection, timing out after specified duration. | |||
pub async fn is_valid(&self, timeout: Duration) -> Result<(), Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since timeouts are so easy in the async world, I'd prefer to only expose this API in the blocking client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Rust allow a module to expose functions to the workspace but not beyond? Otherwise, we would have to introduce async
in the postgres
crate, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not, but that's not a problem. There's already async code in the postgres crate in the block_on calls.
postgres/src/client.rs
Outdated
@@ -413,6 +413,11 @@ impl Client { | |||
self.connection.block_on(self.client.simple_query(query)) | |||
} | |||
|
|||
/// Validates connection, timing out after specified duration. | |||
pub fn is_valid(&mut self, timeout: std::time::Duration) -> Result<(), Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: import Duration
with a use std::time::Duration
up above.
tokio-postgres/src/bind.rs
Outdated
@@ -20,8 +20,9 @@ where | |||
I: IntoIterator<Item = P>, | |||
I::IntoIter: ExactSizeIterator, | |||
{ | |||
type BytesResult = Result<bytes::Bytes, Error>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this change for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the impl From
block was introduced, the compiler required the type hint. Replacing the impl From
block will make this change unnecessary.
tokio-postgres/src/error/mod.rs
Outdated
@@ -492,3 +495,9 @@ impl Error { | |||
Error::new(Kind::Connect, Some(Box::new(e))) | |||
} | |||
} | |||
|
|||
impl From<Elapsed> for Error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather have a #[doc(hidden)]
explicit constructor rather than a From impl.
Thanks! |
This pull request arose from sfackler/r2d2#116.