7 Coroutines and async/await Now that you've gotten a brief introduction to Rust's async model, it's time to take a look at how this fits in the context of everything else we've covered in this book so far. Rust's futures are an example of an asynchronous model based on stackless coroutines, and in this chapter, we'll take a look at what that really means and how it differs from stackful coroutines (fibers/green threads). We'll center everything around an example based on a simplified model of futures and async/ await and see how we can use that to create suspendable and resumable tasks just like we did when creating our own fibers. The good news is that this is a lot easier than implementing our own fibers/green threads since we can stay in Rust, which is safer. The flip side is that it's a little more abstract and ties into programming language theory as much as it does computer science. In this chapter, we'll cover the following: Introduction to stackless coroutines An example of hand-written coroutines async/await Technical requirements The examples in this chapter will all be cross-platform, so the only thing you need is Rust installed and the repository that belongs to the book downloaded locally. All the code in this chapter will be found in the ch07 folder. We'll use delayserver in this example as well, so you need to open a terminal, enter the delayserver folder at the root of the repository, and write cargo run so it's ready and available for the examples going forward.