Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

Setting up the GenServer

We'll begin by using the GenServer macro and setting up some configuration variables on the module:

defmodule Vocial.ChatCache do  use GenServer  @table :presence  @key :statuses

Next, we'll need to implement two GenServer-specific functions, start_link/0 and init/1. start_link/0 is responsible for starting up the GenServer that we're building (and we'll also be giving it a name to make it easier to reference later):

  def start_link do    GenServer.start_link(__MODULE__, [], name: __MODULE__)  end

Then we'll need to implement init/1, which will just create our ETS table that we'll use for storing all of our Presence data over time:

  def init(_) do    table = :ets.new(@table, [:bag])    {:ok, %{table: table}}  end

We're creating ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content