O'Reilly logo

Learning Elixir by Kenny Ballou

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Applications

Now that we have most of the basics of processes in Elixir, let's try out some examples and applications.

There will be a progression through these examples. We will start pretty small and grow in complexity.

Ping pong

Let's start with a very basic example where one process sends a :ping message to another process. The receiving process will send a :pong message in response.

We will start with a module that looks very similar to the module we created for storing state in a process, except that we have no need for state, this module will only listen for the :ping messages and return :pong:

defmodule PingPong do def start_link do spawn_link(fn -> loop() end) end defp loop do receive do {:ping, sender} -> send sender, {:pong, self} end loop ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required