Итак, это часть модуля, который я пишу:
request(Pid, ListOfDocuments) when is_pid(Pid), is_list(ListOfDocuments) ->
io:format("We get here~n"),
case whereis(jdw_api) of
undefined -> [no, api];
ApiPid when is_pid(ApiPid) ->
io:format("... and here~n"),
% (1) Won't work: spawn(?MODULE, loop, [Pid, ListOfDocuments])
% (2) Won't work, either: ?MODULE:loop(Pid, ListOfDocuments)
loop(Pid, ListOfDocuments) % (3) and neither does this...
end.
... и вот так:
loop(Pid, Docs) when is_list(Docs), length(Docs) > 0 ->
H = hd(Docs),
T = tl(Docs),
io:format("... but not here...~w~n", H),
case ?MODE of
sync ->
Ref = make_ref(),
jdw_api ! {self(), Ref, doc, H},
Ans = loop_sync(Ref, [], []),
Pid ! Ans,
loop(Pid, T);
async -> {error, 'async mode not implemented yet', ?FILE, ?LINE};
_ -> {'?MODE must be either async or sync'}
end;
loop(Pid, Docs) -> io:format("Done with document list").
... но по какой-то причине функция "loop" никогда не вызывается. Ни один из трех разных способов не дает магии случиться ... Есть указатели?