Exercises
In the following exercises, you are expected to define several reactor protocols. In some cases, the task is to first investigate a specific algorithm online on your own, and then implement it using the Reactors framework. The exercises are ordered by their difficulty, and range from simple tasks to more complex ones.
Define a method called
twice
, which takes a target channel, and returns a channel that forwards every event twice to the target.def twice[T](target: Channel[T]): Channel[T]
Define a method called
throttle
, which throttles the rate at which events are forwarded to the target channel.def throttle[T](target: Channel[T]): Channel[T]
Hint: you will have to use the
Clock
service and the functional event stream composition.The
Shutdown
service shown in this chapter can run out of memory if there are a lot of reactors subscribing to it. This is because the current implementation never removes entries from the service'ssubscribers
map. Modify the custom...