- Notifications
You must be signed in to change notification settings - Fork514
Improve the documentation of tokio-postgres connect#1099
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…cates the importance of the connection object
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.
Good idea. I've left some minor changes
/// 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.** |
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've cleaned it up a bit.
/// 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.** |
/// | ||
/// [`Config`]: config/struct.Config.html |
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.
This should go below the examples section.
/// # 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 | ||
/// ``` |
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.
/// # 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` | |
/// ``` |
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.