Slide 88
Slide 88 text
defmodule NewBank.CounterServer do
...
# Server
@impl true
def handle_cast(:increment, _from) do
default = 1
value = :ets.update_counter(:counter_table, "counter_key", 1, default)
{:reply, :ok, value}
end
@impl true
def handle_call(:fetch, _from, counter) do
{:reply, :ets.lookup(:counter_table, "counter_key"), counter}
end
end