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

Implementing the cast and call logic

Now we'll need to write our handlers for the cast (async) and call (sync) functions. We'll start with our cast, which inserts the data into the ETS table. handle_cast/2 is a function you need to implement for your GenServer to be able to deal with message casts, which takes in two arguments: the message you're sending (whatever data you're sending), and the current state of the GenServer, which in our case is going to store the table:

  def handle_cast({:write, row}, %{table: table}=state) do    :ets.insert(table, {@key, row})    {:noreply, state}  end

In our write function, we sent the cast with a tuple of the message and the data we wanted to write. The message was :write, and the data was row. We also pattern ...

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