liveBook · Manning

Async runtime

As explained in Rust Web Development

An asynchronous runtime schedules and drives asynchronous tasks, managing their progress and associated execution resources.

An async runtime manages background tasks and their progress, using threads or other mechanisms. In a web server, this helps work continue while the server accepts further requests. section 1.3

In Rust, an async runtime is compiled into static code. Libraries and frameworks choose which runtime to build on, so an application can include more than one. For example, a web framework may use Tokio while an HTTP helper uses another runtime. Any side effects depend on the application’s design. section 1.3

Listing 1.12 Sending HTTP GET requests asynchronously in Rust
// ch_01/minimal_reqwest/src/main.rs
// https:/ /github.com/Rust-Web-Development/code/tree/main/ch_01/minimal_reqwest
 
use std::collections::HashMap;
 
#[tokio::main]                                                #1
async fn main() -> Result<(), Box<dyn std::error::Error>> {   #2
    let resp = reqwest::get("https:/ /httpbin.org/ip")        #3
        .await?;                                              #4
        .json::<HashMap<String, String>>()
        .await?;
    println!("{:#?}", resp);                                  #5
    Ok(())                                                    #6
}

This asynchronous HTTP request uses Tokio for the runtime and Reqwest to fetch and decode a response. section 1.3

How Rust Web Development covers it

How deep it goes
Explains task and thread management and multiple-runtime tradeoffs, while deferring detailed asynchronous code treatment.
Examples
Uses an asynchronous HTTP GET with Tokio and Reqwest and a hypothetical application containing two runtimes.
What you can do after
Evaluate runtime choices and recognize when dependencies may compile multiple runtimes into an application.
How it connects
Connects runtimes to asynchronous programming, threads, kernel abstractions, and web frameworks.

Also explained in

Compare how 3 books explain async runtime →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Web Development. The section links point to the parts of the book it draws on.