Exploring the Tokio framework for async programming
Before we explore what Tokio is and how it works, we should try to execute some async code in normal Rust. Throughout this chapter, we will be building a basic simulation using Tokio. Therefore, the Tokio code that we will be writing is in the simulation
directory as its own Cargo project. Seeing as we are running async
functions in our Rust server code to process views, we can see if we can execute a basic async
function in our main
function in the main.rs
file with the following code:
async fn hello() { println!("Hello, world!"); } fn main() { hello(); }
This looks simple enough; however, if we try to run our main
function, we get the following output:
warning: unused implementer of `Future` that must be used --> src/main.rs:9:5 | 9 | hello(); | ^^^^^^^^ | ...