Skip to content

Commit

Permalink
Name individual game processes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrowah committed Jan 3, 2024
1 parent c6df93d commit 76333ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/islands_engine/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule IslandsEngine.Application do
children = [
# Starts a worker by calling: IslandsEngine.Worker.start_link(arg)
# {IslandsEngine.Worker, arg}
{Registry, keys: :unique, name: Registry.Game}
]

# See https://hexdocs.pm/elixir/Supervisor.html
Expand Down
9 changes: 6 additions & 3 deletions lib/islands_engine/game.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ defmodule IslandEngine.Game do

@players [:player1, :player2]

@spec start_link(binary()) :: :ignore | {:ok, pid()}
@spec via_tuple(String.t()) :: {:via, Registry, {Registry.Game, String.t()}}
def via_tuple(name), do: {:via, Registry, {Registry.Game, name}}

@spec start_link(binary()) :: {:ok, pid()} | :ignore
def start_link(name) when is_binary(name) do
case GenServer.start_link(__MODULE__, name, []) do
case GenServer.start_link(__MODULE__, name, name: via_tuple(name)) do
{:ok, pid} ->
{:ok, pid}

Expand All @@ -19,7 +22,7 @@ defmodule IslandEngine.Game do
end
end

@spec init(any()) ::
@spec init(String.t()) ::
{:ok,
%{
player1: %{board: map(), guesses: map(), name: String.t()},
Expand Down

0 comments on commit 76333ba

Please sign in to comment.