January 2019
Intermediate to advanced
520 pages
14h 32m
English
In the main function implementation, we create a Runtime instance, which we will use for database queries and to process HTTP requests. Look at the following code:
pub fn main() -> Result<(), Error> { let mut runtime = Runtime::new()?; let handshake = tokio_postgres::connect("postgres://postgres@localhost:5432", NoTls); let (mut client, connection) = runtime.block_on(handshake)?; runtime.spawn(connection.map_err(drop)); // ...}
We create a Runtime instance. After that, we can create a new database connection by calling the connect function of the tokio-postgres crate. It returns a Future that we have to execute immediately. To run a Future, we will use the same Runtime we have already created. Runtime has the block_on method, ...
Read now
Unlock full access