Skip to content

Conversation

@JJaviMS
Copy link

@JJaviMS JJaviMS commented Jan 28, 2024

As it can be seen on #924 and from my personal experience, it can be easily missed the use of the connection object when connecting using the tokio-postgres. I have improved the docs for that method so it indicates the importance of the connection object and give an example of how to use it.

…cates the importance of the connection object
Copy link
Member

@paolobarbolini paolobarbolini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I've left some minor changes

Comment on lines +184 to +187
/// This method returns the client which will allow you to interact with the database and a connection
/// object which is the one that performs the communication with the dabase. **It's important to use the
/// connection object as shown in the below example, if it is ignored then the client object will not work
/// and when a .wait is called it will await forever.**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've cleaned it up a bit.

Suggested change
/// This method returns the client which will allow you to interact with the database and a connection
/// object which is the one that performs the communication with the dabase. **It's important to use the
/// connection object as shown in the below example, if it is ignored then the client object will not work
/// and when a .wait is called it will await forever.**
/// This method returns the client object, which will allow you to interact with the database,
/// and a connection object, which performs the communication with the database.
///
/// **The connection object must be actively polled, which is usually done by spawning it into
/// it's own tokio task, as shown below. If this is not done, calls to the client object will hang forever.**

Comment on lines 192 to 193
///
/// [`Config`]: config/struct.Config.html
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go below the examples section.

Comment on lines +195 to +208
/// # Examples
/// ```
/// // Connect to the database.
/// let (client, connection) =
/// tokio_postgres::connect("host=localhost user=postgres", NoTls).await?;
/// // The connection object performs the actual communication with the database,
/// // so spawn it off to run on its own.
/// tokio::spawn(async move {
/// if let Err(e) = connection.await {
/// eprintln!("connection error: {}", e);
/// }
/// });
/// // Use the client
/// ```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// # Examples
/// ```
/// // Connect to the database.
/// let (client, connection) =
/// tokio_postgres::connect("host=localhost user=postgres", NoTls).await?;
/// // The connection object performs the actual communication with the database,
/// // so spawn it off to run on its own.
/// tokio::spawn(async move {
/// if let Err(e) = connection.await {
/// eprintln!("connection error: {}", e);
/// }
/// });
/// // Use the client
/// ```
/// # Examples
///
/// ```
/// // Connect to the database.
/// let (client, connection) =
/// tokio_postgres::connect("host=localhost user=postgres", NoTls).await?;
///
/// // The connection object performs the actual communication with the database,
/// // so spawn it off to run on its own.
/// tokio::spawn(async move {
/// if let Err(e) = connection.await {
/// eprintln!("connection error: {}", e);
/// }
/// });
///
/// // Now we can use the `client`
/// ```

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