Flake: HM module
This commit is contained in:
20
lib/agent.ex
20
lib/agent.ex
@@ -8,10 +8,19 @@ defmodule Frajtano.Agent do
|
||||
|
||||
@impl true
|
||||
def init(_) do
|
||||
{:ok,
|
||||
%{
|
||||
keys: %{}
|
||||
}}
|
||||
{
|
||||
:ok,
|
||||
%{
|
||||
keys: %{}
|
||||
},
|
||||
{:continue, :init_peers}
|
||||
}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_continue(:init_peers, state) do
|
||||
for peer <- Application.fetch_env!(:frajtano, :initial_peers), do: {:ok, _} = Peer.start(peer)
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
@impl true
|
||||
@@ -26,10 +35,9 @@ defmodule Frajtano.Agent do
|
||||
with {:ok, idents} <- Peer.identities(peer),
|
||||
do: {:ok, {idents, peer}}
|
||||
end)
|
||||
|
||||
|
||||
# Double :ok-wrapping because of Task.async_stream
|
||||
idents = (for {:ok, {:ok, {idents, peer}}} <- idents, do: {idents, peer})
|
||||
idents = for {:ok, {:ok, {idents, peer}}} <- idents, do: {idents, peer}
|
||||
|
||||
{
|
||||
:reply,
|
||||
|
||||
@@ -17,10 +17,10 @@ defmodule Frajtano.Supervisor do
|
||||
@impl true
|
||||
def init(:ok) do
|
||||
children = [
|
||||
{DynamicSupervisor, name: Frajtano.Peer},
|
||||
Frajtano.Agent,
|
||||
{Frajtano.Listener, [Application.fetch_env!(:frajtano, :listen_path)]},
|
||||
{Task.Supervisor, name: Frajtano.ClientSupervisor},
|
||||
{DynamicSupervisor, name: Frajtano.Peer}
|
||||
{Frajtano.Listener, [Application.fetch_env!(:frajtano, :listen_path)]},
|
||||
]
|
||||
|
||||
Supervisor.init(children, strategy: :one_for_one)
|
||||
|
||||
Reference in New Issue
Block a user