Я пытаюсь получить ввод от пользователя, а затем создать количество генсерверов в качестве ввода и контролировать их. Мой код что-то вроде
defmodule GossSim do
use Supervisor
def main(args) do
# Since it is a mix generated project I had to put the main
Supervisor.start_link(__MODULE__, args)
end
def start_link(args) do
Supervisor.start_link(__MODULE__, args)
end
#The two methods down below create children dynamically
def get_child_list(child_list, 0), do: child_list
def get_child_list(child_list, num_of_nodes) do
child =
%{
id: :rand.uniform(num_of_nodes*100000),
start: {Gossip_node, :start_link, [[0,true]]}
}
if num_of_nodes > 0 do
get_child_list( [child] ++ child_list, num_of_nodes-1)
end
end
def init(args) do
children = get_child_list([], 10)
# The outut of this inspect is pasted below
IO.inspect children, label: "The children list is"
// some function that does something parse_args_and_start(args)
// num_of_nodes is 10
children = get_child_list([], num_of_nodes)
Supervisor.init(children, strategy: :simple_one_for_one)
end
Я получаю следующую ошибку
bad child specification, invalid children: [%{id: 512, start: {Gossip_node, :start_link, [[0, true]]}, type: :worker}, %{id: 49677, start: {Gossip_node, :start_link, [[0, true]]}, type: :worker},
за которым следует список всех дочерних процессов. Процессы имеют разные идентификаторы
Документ Supervisor говорит, что супервизор в порядке, если у него есть начало и идентификатор. Поскольку дети - это список, я добавляю в него несколько карт детей. Я что-то упускаю. Gossip_node — это модуль в той же папке.