How it works...
In this recipe, we covered how to create a pausable actor that is able to send messages one by one to another actor. We have developed PausableActor with two different behaviors to achieve this purpose. The regular behavior receives a Work message, sends it to the target actor, and calls context.become to change the behavior to pausedBehavior. Once the actor's behavior is pausedBehavior, it no longer sends the Work message to the target actor, but it calls stash() to save it for later processing. Only when the target actor sends back a Ready message does PausableActor call context.unbecome to come back to the previous behavior. It also calls unstashAll() to put back all messages in the mailbox. These messages come back to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access