Skip to content

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

Merged
merged 5 commits into from Dec 18, 2020
Merged

Support connection validation with timeout #711

merged 5 commits into from Dec 18, 2020

Conversation

ghost
Copy link

@ghost ghost commented Dec 11, 2020

This pull request arose from sfackler/r2d2#116.

@@ -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> {
Copy link
Owner

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.

Copy link
Author

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?

Copy link
Owner

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.

@@ -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> {
Copy link
Owner

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.

@@ -20,8 +20,9 @@ where
I: IntoIterator<Item = P>,
I::IntoIter: ExactSizeIterator,
{
type BytesResult = Result<bytes::Bytes, Error>;
Copy link
Owner

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?

Copy link
Author

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.

@@ -492,3 +495,9 @@ impl Error {
Error::new(Kind::Connect, Some(Box::new(e)))
}
}

impl From<Elapsed> for Error {
Copy link
Owner

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.

@sfackler sfackler merged commit 6ed7298 into sfackler:master Dec 18, 2020
@sfackler
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants