[erlang-questions] globaal gen_server stop

Alexander Kuleshov kuleshovmail@REDACTED
Wed Apr 20 09:06:40 CEST 2011


Hello,

I have gen_server:

....
start(User) when is_atom(User) ->
    case gen_server:start({global, User}, server, [], []) of
	{ok, _} ->
	    io:format(User ++ " started");
	{error, Error} ->
	    Error
    end.
.....

My stop function:

stop(User) ->
    gen_server:cast(User, stop).

handle_cast(stop, State) ->
    {stop, normal, State};
handle_cast(_Msg, State) ->
    {noreply, State}.

I run it:

(emacs@REDACTED)199> server:start(asd).
asd started
(emacs@REDACTED)200> server:stop(asd).
ok
(emacs@REDACTED)201> server:start(asd).
{already_started,<0.688.0>}

How can i stop global gen_server by User parameter?

Thank you.



More information about the erlang-questions mailing list