July 2017
Intermediate to advanced
284 pages
6h 45m
English
Elixir runs on the Erlang virtual machine, and Erlang has support for actors built into the language. In fact, the actor model is one of Erlang’s defining characteristics.
And, perhaps surprisingly for something so rich, it’s really simple.
An actor in Elixir is called a process. You create new processes using one of the variants of the spawn function, send messages to it using the <- operator, and receive messages using a receive expression.
Let’s start with spawn:
| | process_id = spawn fn -> |
| | IO.puts "In process #{inspect self()}" |
| | end |
| | IO.puts "Spawned process #{inspect process_id}" |
The spawn function runs the function you pass it as a separate process, returning the process ...
Read now
Unlock full access