DEV Community

Adolfo Neto
Adolfo Neto

Posted on

7

A livebook for the basics of processes in Elixir

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.

Run in Livebook

spawn(fn -> 3 end)
Enter fullscreen mode Exit fullscreen mode
pid = spawn(fn -> 3 end)
Enter fullscreen mode Exit fullscreen mode
Process.alive?(pid)
Enter fullscreen mode Exit fullscreen mode
pid = spawn(fn -> IO.puts("Adolfo") end)
Enter fullscreen mode Exit fullscreen mode
Process.alive?(pid)
Enter fullscreen mode Exit fullscreen mode
Process.sleep(10000)
Enter fullscreen mode Exit fullscreen mode
pid =
  spawn(fn ->
    IO.puts("Starting")
    Process.sleep(10000)
    IO.puts("The end")
  end)
Enter fullscreen mode Exit fullscreen mode
# click evaluate while the process is sleeping
Process.alive?(pid)
Enter fullscreen mode Exit fullscreen mode
defmodule Example do
  def listen do
    receive do
      {:ok, "hello"} -> IO.puts("World")
      _ -> listen()
    end
  end
end
Enter fullscreen mode Exit fullscreen mode
pid = spawn(Example, :listen, [])
Enter fullscreen mode Exit fullscreen mode
Process.alive?(pid)
Enter fullscreen mode Exit fullscreen mode
send(pid, :hi)
Enter fullscreen mode Exit fullscreen mode
send(pid, {:ok, "hello"})
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay