Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Maxwell Flitton, Caroline Morton

Rating No ratings yet

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 learn • How Rust approaches async programming • How coroutines relate to async Rust • Reactive programming and how to implement pub sub in async rust • How to solve problems using actors • How to customize Tokio to gain control over how tasks are processed • Async Rust design patterns • How to build an async TCP server just using the standard library • How to unit test async Rust By 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.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on guide to asynchronous Rust that takes you from the fundamentals of futures and tasks all the way to building your own async runtime, queues, and a dependency-free TCP server. Best for Rust developers who already know the language and want to understand async deeply rather than just use it. 【Book Arc】 - **Opening (~0%–10%)**: Frames what async is and why it matters for I/O-bound work, contrasting blocking vs. asynchronous timelines and situating async within processes, threads, and the OS. - **Early (~10%–35%)**: Introduces the core machinery of async Rust — tasks, futures, async/await, polling, context, wakers, and pinning — culminating in a worked async audit-logger example. - **Middle (~35%–50%)**: Consolidates understanding by building custom async queues from scratch, including multiple queues, task routing, task stealing, join macros, and basic runtime configuration. - **Late (~50%–75%)**: Extends the runtime into networking (executors, connectors, mio, sockets), then explores coroutines and generators, and reactive programming with an event bus. - **Ending (~75%–100%)**: Moves into customizing Tokio (runtime building, local pools, graceful shutdowns), async design patterns, actors, pub/sub, and unit/end-to-end testing of async systems. 【Key Takeaways】 - **Async is about I/O, not raw speed** (Opening): The book positions async as a tool for multitasking around I/O waits, not a universal performance win — useful for choosing the right concurrency model. - **Futures require pinning, context, and wakers** (Early): Understanding why futures can't move in memory and how wakers notify executors is the conceptual core that unlocks everything else. - **Tasks are the unit of async work** (Early): The task-based asynchronous pattern lets you write sequential-looking code that the runtime schedules concurrently. - **Building your own runtime demystifies the black box** (Middle): Implementing queues, task stealing, and join macros reveals how futures actually flow through an executor, making high-level crates easier to reason about. - **Coroutines underpin async/await** (Late): The book draws explicit parallels between coroutines and async tasks, showing async functionality can exist without extra threads. - **Reactive patterns and actors structure complex systems** (Late): Event buses, pub/sub, and actor-based designs are presented as practical ways to organize async communication. - **Tokio is customizable, not monolithic** (Ending): Runtime building, local pools, and graceful shutdowns give fine-grained control over task processing. - **Async code must be tested** (Ending): Unit and end-to-end testing of async systems is treated as a first-class skill, not an afterthought. 【Reading Tips】 - Deep-read the futures/pinning/context material in the early chapters — it's the hardest conceptual hurdle and everything later depends on it. - The networking chapter is flagged by the authors as skippable on a first pass; return to it after the queue-building chapter clicks. - Treat the queue-building chapter as the pivot point: it converts abstract concepts into something you can inspect and modify. - Skim the process/thread comparison if you already know OS concurrency; focus on where async sits relative to it. - Keep the audit-logger and TCP-server examples as reference implementations to adapt for your own projects. 【Coverage Limits】 This guide is based on stratified excerpts covering the preface, table of contents, and early-to-middle chapters; later chapters on Tokio customization, actors, and testing are summarized from the book's stated scope rather than detailed excerpt content.
Page 5
. . . . . . . . . . . . . . . . . . . . . 1 What Is Async? 2 Introduction to Processes 5 What Are Threads? 10 Where Can We Utilize Async? 16 Using Async for...
View in text
Excerpt 2
_code2=$? wait $pid3 exit_code3=$? wait $pid4 exit_code4=$? echo "Task 1 (PID $pid1) exited with code $exit_code1" echo "Task 2 (PID $pid2) exited with code...
View in text
Excerpt 3
tes before the next begins. For instance, let’s think about making a cup of coffee and toast, which requires the following steps: 1. Put bread in toaster 2....
View in text
Excerpt 4
t All Together | 45 CHAPTER 3 Building Our Own Async Queues Although we have explored basic async syntax and solved a problem using high-level async concepts...
View in text
Excerpt 5
ent for the order, giving the following function signature: fn spawn_task<F, T>(future: F, order: FutureType) -> Task<T> where F: Future<Output = T> + Send +...
View in text
Excerpt 6
atch stream.read(&mut buffer) { Ok(n) if n > 0 => { received_data.extend_from_slice(&buffer[..n]); Introducing mio | 85 Introducing Coroutines Before we can...
View in text
Excerpt 7
coroutines. Mimicking Async Behavior with Coroutines | 103 Nothing is stopping NestingFuture from having a vector of other futures that update their own valu...
View in text
Excerpt 8
is still blocking. We can make our callbacks nonblocking to the main thread by using an event loop thread that is a constant loop. This loop then accepts inc...
View in text
Tags
AI categories
RustProgramming LanguageBackend
ISBN: 1098149092
Publisher: O'Reilly Media
Publish Year: 2024
Language: English
Pages: 264
File Format: PDF
File Size: 3.7 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…