Communication

Receiving a message

To receive a reply from an actor there are two possibilities:

  1. asynchronous bidirectional communication and
  2. synchronous bidirectional communication.
API functionbrief description
receiveafter a send receive the response asynchronously
requestsend (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.receiveFunction
receive(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}: Msg type,
  • from::Link: local or remote link of sender. If from is provided, only messages with a from field can be matched.
  • timeout::Real=5.0: maximum waiting time in seconds.
    • If timeout==0, lk is scanned only for existing messages.
    • Set timeout=Inf if you don't want to timeout.

Returns

  • received message or Timeout().
source
Actors.requestFunction
request(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

  • lk::Link: actor link, or name::Symbol (if registered),
  • msg::Msg: a message,
  • Msg::Type{<:Msg}: a message type,
  • args...: optional arguments to Msg,
  • full: if true return the full Response message.
  • timeout::Real=5.0: timeout in seconds after which a Timeout is returned,
  • kwargs...: full or timeout.
source

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_afterFunction
send_after(lk::Link, time::Real, msg...)

Send a message msg... to an actor lk (or registered name) after a time period in seconds.

source