Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Chapter 1

chapter01.livemd

Chapter 1

Sum server using Agent

defmodule SumAgent do
  use Agent

  def start_link do
    Agent.start_link(fn -> nil end, name: __MODULE__)
  end

  def sum(a, b) do
    Agent.get(__MODULE__, fn _ -> a + b end)
  end
end
{:module, SumAgent, <<70, 79, 82, 49, 0, 0, 10, ...>>, {:sum, 2}}
SumAgent.start_link()
{:ok, #PID<0.166.0>}
SumAgent.sum(5, 3)
8