[erlang-questions] globaal gen_server stop

Essien Essien essiene@REDACTED
Wed Apr 20 09:16:13 CEST 2011


On Wed, Apr 20, 2011 at 8:06 AM, Alexander Kuleshov
<kuleshovmail@REDACTED> wrote:
> 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).

>From the man page, when calling global gen_server, server ref must be
{global, Name}, so:

      gen_server:cast({global, 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.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list