May 2017
Intermediate to advanced
414 pages
13h
English
In the previous recipe, we created an actor which calculates the sum of integers:
val actor = actorSystem.actorOf(Props[SummingActor], "summingactor")
Now, we will send messages as integers to the summing actor, as follows:
actor ! 1
The following will be the output:
My state as sum is 1
If we keep on sending messages inside a while loop, the actor will continue to calculate the sum incrementally:
while (true) { Thread.sleep(3000) actor ! 1 }
On sending messages inside a while loop, the following output will be displayed:
my state as sum is 1my state as sum is 2my state as sum is 3my state as sum is 4my state as sum is 5
If we send a string message Hello, this message will fall into the actor's default behavior ...
Read now
Unlock full access