| 1 |
|
defmodule Elita.Place do |
| 2 |
|
import DynamicSupervisor, only: [start_child: 2] |
| 3 |
|
import Utils.Normalize, only: [name: 1] |
| 4 |
|
|
| 5 |
|
def put(spec, n) do |
| 6 |
:-( |
start_child(Elita.Spawner, spec) |> swap(n) |
| 7 |
|
end |
| 8 |
|
|
| 9 |
:-( |
defp swap({:ok, _pid}, n), do: find(:global.whereis_name({name(n), :puppet})) |
| 10 |
|
|
| 11 |
|
defp swap({:error, {:already_started, _pid}}, n), |
| 12 |
:-( |
do: find(:global.whereis_name({name(n), :puppet})) |
| 13 |
|
|
| 14 |
:-( |
defp swap(other, _n), do: other |
| 15 |
|
|
| 16 |
:-( |
defp find(:undefined), do: {:error, :init_failed} |
| 17 |
|
|
| 18 |
:-( |
defp find(pid), do: {:ok, pid} |
| 19 |
|
end |