所以,這兒是個模塊,我寫的一部分:模塊功能
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").
...但由於某種原因,「循環」功能永遠不會被調用。三種不同的方式都不會使魔法發生......任何指針?
你是什麼意思「永遠不會叫」?什麼都沒有發生,或者進程崩潰,或者什麼? @archaelus提到的`H`和`[H]`錯誤會導致進程崩潰,如果它沒有鏈接到任何東西,那麼崩潰將是沉默的。 – rvirding 2011-02-10 23:21:05