Actors are the basic building blocks of concurrent computation. In response to a message it receives, an actor can make local decisions, create more actors, send more messages, and determine how to reply to the next message received. Actors may modify their own private state, but can only affect each other indirectly through messaging.
Messages sent to an actor are put into a private message inbox. The actor will take each of these messages and process them sequentially by applying them to the actor's message handler function. The result of the message handler function may be given back to the sender of the message (ASK pattern, see below).
There are two different patterns to communicate with an actor:
==The TELL pattern==
When using the TELL pattern, we just send a single message to the actor (which is very fast) and forget about it. No response is expected to be returned by the actor. This pattern is used for asynchronous communication, as it is not guaranteed when the message will be processed by the actor. The message is put at the back of the actor's message queue and processed when all other messages have been processed.
===The ASK pattern==
The ASK pattern is used when a response is required from the actor (synchronous communication). A single message is sent to the actor and the current process (the caller) is suspended until the actor has processed the message and returned a response.
Interacting with an actor is effectful. This is why all actor functions (tell, ask, terminate) are wrapped into an effect type.
Type parameters
- M
-
The actor's base message type (message handler input)
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any