The following code is liberally borrowed from
where common.conf is
executor = "thread-pool-executor"
type = PinnedDispatcher
The PinnedDispatcher is required since StdInDriver will be blocking on the stdin read and thus requires a dedicated thread.
The above code is implicitly switching between read command and await response modes.
We can make that explicit by using
The above code contains repeated references to prompt(), context.become(awaitResponse).
Those are both ugly and error prone. The three cases can be extracted as follows, eliminating
Finally, the above code terminates with an exception if the user does not enter a integer parameter for the count command.
We can resolve this by defining an extractor
and changing the case to
The complete code is then