Search code examples
scalaakkaactor

How does tell() work in Akka actor system?


I am bit confused looking at the docs here and here

receive() is a method which accepts no parameters and returns a Partial function. tell() is a method which returns Unit and it 'sends' the message. Now for the message to be processed in my understanding 2 things have to happen:

  1. The receive() should be invoked by tell
  2. The message is passed to the partial function which is returned by the receive()

Now if the partial function is returned back to the place where tell() was used, then how does message based communication work? Why isn't the operation being performed inside the actor itself?


Solution

  • Because it is internals there is no documentation, but you can checkout source code yourself here: https://github.com/akka/akka/blob/master/akka-actor/src/main/scala/akka/actor/ActorCell.scala. All internals starting from how tell sends message to mailbox, how message is extracted from it, how receive is called and so on is here.

    Hope it answers your question.