[erlang-questions] using guards in gen_server

Joseph Wayne Norton <>
Sun Aug 29 11:49:17 CEST 2010


I'd place the guards in the API functions.  Let the caller crash rather  
than the server.

On Sun, 29 Aug 2010 18:20:56 +0900, Zvi <> wrote:

> Hi,
>
> When writing gen_server, do you put validation guards in API functions
> or in handle_call / cast or in both ? What's the convention?
>
> For example:
>
> send(Pid) when is_pid(Pid) ->
>    gen_server:call(?SERVER, {send, Pid}).
>
> handle_call({send, Pid}, _From, _State) ->
>    Resp = do_send(Pid),
>    {reply,  Resp, State}.
>
> OR:
>
> send(Pid) ->
>    gen_server:call(?SERVER, {send, Pid}).
>
> handle_call({send, Pid}, _From, _State) when is_pid(Pid) ->
>    Resp = do_send(Pid),
>    {reply,  Resp, State}.
>
> OR:
>
> send(Pid) when is_pid(Pid) ->
>    gen_server:call(?SERVER, {send, Pid}).
>
> handle_call({send, Pid}, _From, _State) when is_pid(Pid) ->
>    Resp = do_send(Pid),
>    {reply,  Resp, State}.
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>


-- 



More information about the erlang-questions mailing list