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

Creating the public interface for the GenServer

Next, we'll need two utility functions to abstract away some of the GenServer logic. We'll start by creating the function responsible for writing new data to our ETS Presence cache:

  def write(topic, username, status) do    row = %{      topic: topic,      username: username,      status: status,      timestamp: DateTime.utc_now()    }    GenServer.cast(__MODULE__, {:write, row})  end

This function isn't doing nearly as much as it looks like it's doing: It takes in the topic, the user's username, and the status we want to record, builds a map from these, which includes the current timestamp, and then uses a GenServer message cast (an asynchronous call) to itself to write that row. We'll deal with this message later!

lookup ...

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