Already popular among programmers for its memory safety and speed, the Rust programming language is also valuable for asynchrony. This practical book shows you how asynchronous Rust can help you solve problems that require multitasking. You'll learn how to apply async programming to solve problems with an async approach. You will also dive deeper into async runtimes, implementing your own ways in which async runtimes handle incoming tasks.
Authors Maxwell Flitton and Caroline Morton also show you how to implement the Tokio software library to help you with incoming traffic, communicate between threads with shared memory and channels, and design a range of complex solutions using actors. You'll also learn to perform unit and end-to-end tests on a Rust async system.
With this book, you'll
How Rust approaches async programmingHow coroutines relate to async RustReactive programming and how to implement pub sub in async rustHow to solve problems using actorsHow to customize Tokio to gain control over how tasks are processedAsync Rust design patternsHow to build an async TCP server just using the standard libraryHow to unit test async RustBy the end of the book, you'll be able to implement your own async TCP server completely from the standard library with zero external dependencies, and unit test your async code.
In short, nothing interesting if you have coded in Rust. If you are just getting started, you are at risk of learning from bad examples/use cases.
-- Most examples are not realistic; examples of when to use some async concept are bad.
My point here is that an experienced developer just filters out bad examples. But if the book is read by a beginner, they will start using this approach without understanding! The book is full of bad examples and bad explanations.
One example is in the coroutine chapter. Where it was used to improve this function ``` fn append_number_to_file(n: i32) -> io::Result<()> { let mut file = OpenOptions::new() .create(true) .append(true) .open("numbers.txt")?; writeln!(file, "{n}")?; Ok(()) } ``` Instead of opening a file on every call, he used a coroutine. It is so unrealistic and a bad example. And showing 4sec -> 0.6sec improvement is so stupid. When in reality one can just pass ref to buffered file and have 0.009 sec execution time. With simple sync code. He also mentioned threads to speedup execution... that is so irrelivant!
This book is kickstarter into the overall idea of async and offers both perspectives of writing an async runtime from scratch alongs with the frutre traits, but also manages to explain to me why I'd like to use something like Tokio.
Mid of the book I wondered how all the topics are supposed to work to a common goal, but this is ultimately clear after the last chapters, where everything comes magically togehter.