O'Reilly logo

Functional Web Development with Elixir, OTP, and Phoenix by Lance Halvorsen

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

Getting Started with GenServer

GenServers are everywhere in Elixir code. Becoming proficient with GenServer is one of the best things you can do to level up as an Elixir developer. It will require some work on your part. You’ll need to learn how client functions, module functions, and callbacks work and interact.

But honestly, implementing a GenServer is pretty straightforward. We’ll get lots of practice in this chapter, so you’ll come out of it knowing your way around.

Let’s begin with a new file in the lib directory called lib/islands_engine/game.ex. This will define a new module that will become our GenServer.

 defmodule​ IslandsEngine.Game ​do
 use​ GenServer
 end

By adding the use GenServer line, we already have the beginnings of ...

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