Slide 13
Slide 13 text
GenServer
defmodule Collab.Document do
use GenServer
alias Collab.Document.Supervisor
def start_link(id), do: GenServer.start_link(
__
MODULE
__
, :ok, name: name(id))
def get_contents(id), do: GenServer.call(name(id), :get_contents)
def update(id, data), do: GenServer.call(name(id), {:update, change, ver})
def open(id) do
case GenServer.whereis(name(id)) do
nil
->
DynamicSupervisor.start_child(Supervisor, {
__
MODULE
__
, id})
pid
->
{:ok, pid}
end
end
defp name(id), do: {:global, {:doc, id}}
end
13