Step 3 – Implementing a proper Reactor
The final part of our example is the Reactor
. Our Reactor
will:
- Efficiently wait and handle events that our runtime is interested in
- Store a collection of
Waker
types and make sure to wake the correctWaker
when it gets a notification on a source it’s tracking - Provide the necessary mechanisms for leaf futures such as
HttpGetFuture
, to register and deregister interests in events - Provide a way for leaf futures to store the last received
Waker
When we’re done with this step, we should have everything we need for our runtime, so let’s get to it.
Start by opening the reactor.rs
file.
The first thing we do is add the dependencies we need:
ch08/b-reactor-executor/src/runtime/reactor.rs
use crate::runtime::Waker; use mio::{net::TcpStream, Events, Interest, Poll, Registry, Token}; use std::{ collections::HashMap, sync::{ ...