defmodule Tgapi.Session do
use GenServer
def start_link(name) do
GenServer.start_link(__MODULE__, %{}, name: name)
end
def put(pid, key, value) do
GenServer.cast(pid, {:put, key, value})
end
def get(pid, key) do
GenServer.call(pid, {:get, key})
end
def delete(pid, key) do
GenServer.cast(pid, {:delete, key})
end
@impl true
def init(%{}) do
{:ok, %{}}
end
@impl true
def handle_call({:get, key}, _from, state) do
{:reply, Map.get(state, key), state}
end
@impl true
def handle_cast({:put, key, value}, state) do
{:noreply, Map.put(state, key, value)}
end
@impl true
def handle_cast({:delete, key}, state) do
{:noreply, Map.delete(state, key)}
end
end