【发布时间】:2016-05-29 17:45:20
【问题描述】:
在LYSE一书中作者对服务器的终止处理如下:
%% Synchronous call
close_shop(Pid) -> gen_server:call(Pid, terminate).
handle_call(terminate, _From, Cats) ->
{stop, normal, ok, Cats}.
terminate(normal, Cats) ->
[io:format("~p was set free.~n",[C#cat.name]) || C <- Cats],
ok.
所以它从handle_call 回调中返回一个stop 值。
我是这样写的:
close_shop(Pid) -> gen_server:stop(Pid).
terminate(_Reason, {Cats, Money}) ->
io:format("Made $~w~n", [Money]),
[io:format("~p was set free.~n",[C#cat.name]) || C <- Cats].
那么直接拨打gen_server:stop()不是一个好习惯吗?
【问题讨论】:
标签: erlang erlang-otp gen-server