O'Reilly logo

Actors in Scala by Frank Sommers, Philipp Haller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.3 Sending actor messages

At this point, ChatRoom is ready to process subscription messages, so let's send some messages to it. Scala's actors library supports both asynchronous and synchronous message sending.

Asynchronous message sending

You send a message asynchronously to an actor with the bang (!) symbol. In using ! to denote message sending, Scala follows the tradition of Erlang:

  val chatRoom = new ChatRoom
  chatRoom ! Subscribe(User("Bob"))

The ! method sends a message to chatRoom and returns immediately; it doesn't wait for any confirmation or reply from the target actor. In addition to the message, ! also sends an implicit reference to the sender to the target actor. That reference is always available inside the target actor via the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required