I'll briefly list what we need to do to get this working here:
- We need a thread pool to execute our CPU intensive tasks or tasks that we want to run asynchronously but not in our OS backed event queue
- We need to make a simple cross platform
epoll/kqueue/IOCPevent loop. Now this turns out to be extremely interesting, but it's also a lot of code, so I split this section off into a separate "companion book" for those that want to explore this further. We use this library here called
Granted, we're breaking our rule that we don't use any dependencies, but it's our own dependency which we'll explain fully in due time.
Our runtime will:
- Store our callbacks to be run at a later point
- Send tasks to be executed on the thread pool
- Register interests with the OS (through
- Poll our two event sources for new events
- Handle timers
- Provide a way for "modules" like
Cryptoto register tasks
- Progress all our tasks until we're finished
- For handling file system tasks
- For handling http calls
- For handling cryptological tasks
We need some helpers to make our code readable and to provide the output we want to see. In contrast to any real runtime, we're interested in knowing what happens and when. To help with that we define three extra methods:
print_content does the same as
current is just a shortcut for us to get the name of the current thread. Since we want to track what's happening, we're going to need to print out which thread is issuing what output, so this will avoid cluttering up our code too much along the way.
Minimio is a cross platform epoll/kqueue/IOCP based event loop that we will cover in the next book. I originally included it here, but implementing that for three architectures turned out to be a bit more involved than I first thought and needed more space than would fit in this book.
It's also easier to just read up on epoll/kqueue/IOCP when it's concentrated in a separate book.