Communication
Receiving a message
To receive a reply from an actor there are two possibilities:
- asynchronous bidirectional communication and
- synchronous bidirectional communication.
| API function | brief description |
|---|---|
receive | after a send receive the response asynchronously |
request | send (implicitly) a message to an actor, block and receive the response synchronously |
Both calls block until a message is received or until it times out.
Actors.receive — Functionreceive(lk; timeout=5.0)
receive(lk, from; timeout=5.0)
receive(lk, M; timeout=5.0)
receive(lk, M, from; timeout=5.0)Receive a message over a link lk.
If M or from are provided, receive returns only a matching message. Other messages in lk are restored to it in their previous order.
Parameters
lk::Link: local or remote link over which the message is received,M::Type{<:Msg}:Msgtype,from::Link: local or remote link of sender. Iffromis provided, only messages with afromfield can be matched.timeout::Real=5.0: maximum waiting time in seconds.- If
timeout==0,lkis scanned only for existing messages. - Set
timeout=Infif you don't want to timeout.
- If
Returns
- received message or
Timeout().
Actors.request — Functionrequest(lk::Link, msg::Msg; full=false, timeout::Real=5.0)
request(lk::Link, M::Type{<:Msg}, args...; kwargs...)Send a message to an actor, block, receive and return the result.
Arguments
Delays
An actor should be responsive. Therefore you should avoid to sleep within behavior functions. For delayed actions an actor can send instead a delayed message with send_after to other actors or to self().
Actors.send_after — Functionsend_after(lk::Link, time::Real, msg...)Send a message msg... to an actor lk (or registered name) after a time period in seconds.