The basics of processes in Elixir
Examples
All you have to do is to open a Livebook server and import this notebook, by clicking on the button below.
spawn(fn -> 3 end)
pid = spawn(fn -> 3 end)
Process.alive?(pid)
pid = spawn(fn -> IO.puts("Adolfo") end)
Process.alive?(pid)
Process.sleep(10000)
pid =
spawn(fn ->
IO.puts("Starting")
Process.sleep(10000)
IO.puts("The end")
end)
# click evaluate while the process is sleeping
Process.alive?(pid)
defmodule Example do
def listen do
receive do
{:ok, "hello"} -> IO.puts("World")
_ -> listen()
end
end
end
pid = spawn(Example, :listen, [])
Process.alive?(pid)
send(pid, :hi)
send(pid, {:ok, "hello"})
Top comments (0)