Async Rust: Unleashing the Power of Fearless Concurrency

Async Rust: Unleashing the Power of Fearless Concurrency

Async Rust: Unleashing the Power of Fearless Concurrency
Автор: Flitton Maxwell, Morton Caroline
Дата выхода: 2025
Издательство: O’Reilly Media, Inc.
Количество страниц: 264
Размер файла: 1,3 МБ
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы

Cover
Copyright
Table of Contents
Preface
What Is Async Rust?
Who Is This Book For?
Overview of the Chapters
Conventions Used in This Book
O’Reilly Online Learning
How to Contact Us
Acknowledgments
Maxwell
Caroline
Chapter 1. Introduction to Async
What Is Async?
Introduction to Processes
What Are Threads?
Where Can We Utilize Async?
Using Async for File I/O
Improving HTTP Request Performance with Async
Summary
Chapter 2. Basic Async Rust
Understanding Tasks
Futures
Pinning in Futures
Context in Futures
Waking Futures Remotely
Sharing Data Between Futures
High-Level Data Sharing Between Futures
How Are Futures Processed?
Putting It All Together
Summary
Chapter 3. Building Our Own Async Queues
Building Our Own Async Queue
Increasing Workers and Queues
Passing Tasks to Different Queues
Task Stealing
Refactoring Our spawn_task Function
Creating Our Own Join Macro
Configuring Our Runtime
Running Background Processes
Summary
Chapter 4. Integrating Networking into Our Own Async Runtime
Understanding Executors and Connectors
Integrating hyper into Our Async Runtime
Building an HTTP Connection
Implementing the Tokio AsyncRead Trait
Implementing the Tokio AsyncWrite Trait
Connecting and Running Our Client
Introducing mio
Polling Sockets in Futures
Sending Data over the Socket
Summary
Chapter 5. Coroutines
Introducing Coroutines
What Are Coroutines?
Why Use Coroutines?
Generating with Coroutines
Implementing a Simple Generator in Rust
Stacking Our Coroutines
Calling a Coroutine from a Coroutine
Mimicking Async Behavior with Coroutines
Controlling Coroutines
Testing Coroutines
Summary
Chapter 6. Reactive Programming
Building a Basic Reactive System
Defining Our Subjects
Building Our Display Observer
Building Our Heater and Heat-Loss Observer
Getting User Input via Callbacks
Enabling Broadcasting with an Event Bus
Building Our Event Bus Struct
Building Our Event Bus Handle
Interacting with Our Event Bus via Async Tasks
Summary
Chapter 7. Customizing Tokio
Building a Runtime
Processing Tasks with Local Pools
Getting Unsafe with Thread Data
Graceful Shutdowns
Summary
Chapter 8. The Actor Model
Building a Basic Actor
Working with Actors Versus Mutexes
Implementing the Router Pattern
Implementing State Recovery for Actors
Creating Actor Supervision
Summary
Chapter 9. Design Patterns
Building an Isolated Module
Waterfall Design Pattern
The Decorator Pattern
The State Machine Pattern
The Retry Pattern
The Circuit-Breaker Pattern
Summary
Chapter 10. Building an Async Server with No Dependencies
Setting Up the Basics
Building Our std Async Runtime
Building Our Waker
Building Our Executor
Running Our Executor
Building Our Sender
Building Our Receiver
Building Our Sleep
Building Our Server
Accepting Requests
Handling Requests
Building Our Async Client
Summary
Chapter 11. Testing
Performing Basic Sync Testing
Mocking Async Code
Testing For Deadlocks
Testing for Race Conditions
Testing Channel Capacity
Testing Network Interactions
Fine-Grained Future Testing
Summary
Index
About the Authors
Colophon

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.


Похожее:

Список отзывов:

Нет отзывов к книге.