Step 2 – Implementing a proper Executor
In this step, we’ll create an executor that will:
- Hold many top-level futures and switch between them
- Enable us to spawn new top-level futures from anywhere in our asynchronous program
- Hand out
Waker
types so that they can sleep when there is nothing to do and wake up when one of the top-level futures can progress - Enable us to run several executors by having each run on its dedicated OS thread
Note
It’s worth mentioning that our executor won’t be fully multithreaded in the sense that tasks/futures can’t be sent from one thread to another, and the different Executor
instances will not know of each other. Therefore, executors can’t steal work from each other (no work-stealing), and we can’t rely on executors picking tasks from a global task queue.
The reason is that the Executor
design will be much more complex if we go down that route, not only because of the added...