Table of Contents x What the Rust language and standard library take care of 133I/O vs CPU-intensive tasks 134 Summary 135 7 Coroutines and async/await 137 Technical requirements 137 Introduction to stackless coroutines 138 An example of hand-written coroutines 139 Futures module 141 HTTP module 142 Do all futures have to be lazy? 146 Creating coroutines 147async/await 154 coroutine/wait 155 corofy—the coroutine preprocessor 155 b-async-await—an example of a coroutine/ wait transformation 156 c-async-await—concurrent futures 160 Final thoughts 165 Summary 166 8 Runtimes, Wakers, and the Reactor-Executor Pattern 167 Technical requirements 168 Introduction to runtimes and why we need them 169 Reactors and executors 170 Improving our base example 171 Design 173 Changing the current implementation 177 Creating a proper runtime 184 Step 1-Improving our runtime design by adding a Reactor and a Waker 187 Creating a Waker 188Changing the Future definition 191 Step 2-Implementing a proper Executor 192 Step 3-Implementing a proper Reactor 199 Experimenting with our new runtime 208 An example using concurrency 208 Running multiple futures concurrently and in parallel 209 Summary 211