April 2018
Beginner to intermediate
406 pages
9h 33m
English
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 ...