February 2018
Intermediate to advanced
552 pages
13h 46m
English
Consider that an Actor-1 sends a message to Actor-2 using the ask function to know the response from that Actor; it is as shown here:
actor1 ? HelloMessage
In Actor-2, when it receives it, it should process it and reply to that Actor-2, as shown here:
def receive = {
case HelloMessage =>
println("Actor-2: Process the message")
sender ! HowDoYouDo
}
Here, Actor-2 uses the sender object to reply with a message back to that message sender directly.
Here, sender is a function defined in an Actor trait to access the current processing message's sender Actor reference directly, as follows:
final def sender(): ActorRef = context.sender()
Read now
Unlock full access