What is the difference between exclamation mark (!
) and question mark (?
) when sending messages to Actors?
myActor ! Hello(value1)
myActor ? Hello(value1)
What is the difference between exclamation mark (!
) and question mark (?
) when sending messages to Actors?
myActor ! Hello(value1)
myActor ? Hello(value1)
From the recipient's point of view, it sees
tell
andask
messages the same way. However when receiving atell
the value ofsender
will be the reference of the actor who sent the message, whereas for anask
, thesender
is set up such that any reply goes to theFuture
created in the actor who did the asking.There is an advantage in
ask
, that it is easy to know that the response you're receiving was definitely a result of the message you asked, whereas with Tell, you may need to use unique IDs to achieve a similar result. However withask
you need to set atimeout
after which theFuture
will fail if no response is received.In the code below, the same effect is achieved with a
tell
and andask
.Shamelessly copied [awesome] official doc (look Send messages section for more):