This website collects cookies to deliver better user experience
Processes in Elixir
Processes in Elixir
spawn
The basic mechanism for spawning new processes is the auto-imported spawn/1 function:
iex> spawn(fn -> 1 + 2 end)
# PID<0.43.0>
Notice spawn/1 returns a PID (process identifier). At this point, the process you spawned is very likely dead. The spawned process will execute the given function and exit after the function is done:
When a message is sent to a process, the message is stored in the process mailbox. The receive/1 block goes through the current process mailbox searching for a message that matches any of the given patterns
Receiver
iex(8)> receive do
...(8)> {:hello,pid}->"Got hello form #{inspect pid}"
...(8)> end
"Got hello form #PID<0.115.0>"