As we learned previously, event streams always propagate events on a single thread. This is useful from the standpoint of program comprehension, but we still need a way to express concurrency in our programs. In this section, we will see how to achieve concurrency by using entities called reactors.
A reactor is the basic unit of concurrency. While actors receive messages, we will adopt the terminology in which reactors receive events, in order to disambiguate. However, while an actor a in particular state has only a single point where it can receive a message, namely, the
receive statement, a reactor can receive an event from many different sources at any time. Despite this flexibility, one reactor will always process, at most, one event at any time. We say that events received by a reactor are serialized, similar to how messages received by an actor are serialized.
To be able to create new reactors, we need a
ReactorSystem object, which tracks reactors in a single machine: