I started this week with this programming language and I'm trying to do a very simple web server for a subject on my university. I have a question when I spawn a process. I need to spawn N process, so I create a function inside my module dispatcher.erl:
create_workers(NWorkers, Servers, Manager, Dispatcher_Pid) ->
case NWorkers of
0 -> Servers;
_ when NWorkers > 0 ->
Process_Pid = spawn(server, start, [Manager]),
create_workers((NWorkers - 1), lists:append(Servers, [{server, Process_Pid}]), Manager, Dispatcher_Pid)
end.
The function I'm trying to call is in another module (server.erl), which contains this code:
start(Manager, Dispatcher_Pid) ->
receive
{request, Url, Id, WWW_Root} ->
case file:read_file((WWW_Root ++ Url)) of
{ok, Msg} ->
conn_manager:reply(Manager, {ok, binary:bin_to_list(Msg)}, Id);
{error, _} ->
conn_manager:reply(Manager, not_found, Id)
end
end,
Dispatcher_Pid ! {done, self()},
start(Manager, Dispatcher_Pid).
So, I'm trying to spawn a process from the dispatcher.erl module to a function on server.erl module, but I get this error on every spawn:
=ERROR REPORT==== 24-Mar-2015::01:42:43 ===
Error in process <0.165.0> with exit value: {undef,[{server,start,[<0.159.0>],[]}]}
I don't know what is happening here, because I think I'm calling the spawn function as the Erlang documentation says, can I get some help?
Thanks for your time!
Okay, I resolved it from myself. When I spawn a new process, I was passing it less arguments than the arity of the function I'm trying to spawn.