Runtimes, Wakers, and the Reactor-Executor Pattern 206 let s = String::from_utf8_lossy(&self. buffer); runtime::reactor(). deregister(self. stream. as_mut(). unwrap(), self. id); break Poll State::Ready(s. to_string()); } Ok(n) => { self. buffer. extend(&buff[0..n]); continue; } Err(e) if e. kind() == Error Kind::Would Block => { runtime::reactor(). set_waker(waker, self. id); break Poll State::Not Ready; } Err(e) => panic!("{e:?}"), } The first change is to deregister the stream from our Poll instance when we're done. The second change is a little more subtle. If you read the documentation for Future::poll in Rust (https://doc. rust-lang. org/stable/std/future/trait. Future. html#tymethod. poll ) carefully, you'll see that it's expected that the Waker from the most recent call should be scheduled to wake up. That means that every time we get a Would Block error, we need to make sure we store the most recent Waker. The reason is that the future could have moved to a different executor in between calls, and we need to wake up the correct one (it won't be possible to move futures like those in our example, but let's play by the same rules). And that's it! Congratulations! Y ou've now created a fully working runtime based on the reactor-executor pattern. Well done! Now, it's time to test it and run a few experiments with it. Let's go back to main. rs and change the main function so that we get our program running correctly with our new runtime. First of all, let's remove the dependency on the Runtime struct and make sure our imports look like this: ch08/b-reactor-executor/src/main. rs mod future; mod http; mod runtime;