M.Regmi M.Regmi - 25 days ago 19
Scala Question

Difference between Akka ask and tell Pattern?

What I found after reading akka documentation is:Ask will send message and

return the future and waits until timeout.Similarly,Tell will send message and

return immediately.I found both same because In both cases the request will be

spawned asynchronously and must wait for a response.What does Tell actually

return?In which case using Ask is better than using Tell and vice versa?

Answer

When your actor Ask() to another actor waits for a reply (the Future you mention) and will eventually pause execution till the Future value is available. When your actor Tell() something to another actor, it just throws the message, does not expect a reply and continues its execution.

So the first is better suited for information requests between actors, the other for bare information sending. It's up to you decide what's the best for the program you are working on.

Comments