Create Your Own Event Queue 70 Poll is a struct that represents the event queue itself. It has a few methods: new : Creates a new event queue registry : Returns a reference to the registry that we can use to register interest to be notified about new events poll : Blocks the thread it's called on until an event is ready or it times out, whichever occurs first Registry is the other half of the equation. While Poll represents the event queue, Registry is a handle that allows us to register interest in new events. Registry will only have one method: register. Again, we mimic the API mio uses (https:// docs. rs/mio/0. 8. 8/mio/struct. Registry. html ), and instead of accepting a predefined list of methods for registering different interests, we accept an interests argument, which will indicate what kind of events we want our event queue to keep track of. One more thing to note is that we won't use a generic type for all sources. We'll only implement this for Tcp Stream, even though there are many things we could potentially track with an event queue. This is especially true when we want to make this cross-platform since, depending on the platforms you want to support, there are many types of event sources we might want to track. mio solves this by having Registry::register accept an object implementing the Source trait that mio defines. As long as you implement this trait for the source, you can use the event queue to track events on it. In the following pseudo-code, you'll get an idea of how we plan to use this API: let queue = Poll::new(). unwrap(); let id = 1; // register interest in events on a Tcp Stream queue. registry(). register(&stream, id,... ). unwrap(); let mut events = Vec::with_capacity(1); // This will block the curren thread queue. poll(&mut events, None). unwrap(); //... data is ready on one of the tracked streams Y ou might wonder why we need the Registry struct at all. To answer that question, we need to remember that mio abstracts over epoll, kqueue, and IOCP. It does this by making Registry wrap around a Selector object. The Selector object is conditionally compiled so that every platform has its own Selector implementation corresponding to the relevant syscalls to make IOCP, kqueue, and epoll do the same thing.