[erlang-questions] How to write a handle_call for gen_server callback with checking user?

Jeroen Koops <>
Fri Apr 2 09:08:39 CEST 2010


You could change it into:

handle_call({start, User, Passwd, Algorithm, ScheduledTime, XmlParams},
_From, State) ->
   case check_user(User, Passwd) of
                   false ->
                       { reply, {error, rejected}, State };
                   _ ->
                       ?INFOLOG("Received request from user ~p for
~p.~n",[User,Algorithm])
                       % other code for processing user request...
                       % other code for processing user request...
                       { reply, { ok, SomeResponse }, State }
                   end
   end.

... if that's what you mean.

Regards,

Jeroen


On Fri, Apr 2, 2010 at 12:29 AM, 钱晓明 <> wrote:

> Just a simple question! My handle_call just like this:
>
> handle_call({start, User, Passwd, Algorithm, ScheduledTime, XmlParams},
> _From,
> State) ->
>    Reply = case check_user(User, Passwd) of
>                    false ->
>                        {error, rejected};
>                    _ ->
>                        ?INFOLOG("Received request from user ~p for ~p.~n",
> [User,Algorithm])
>                        % other code for processing user request...
>                        % other code for processing user request...
>                    end,
>    {reply, Reply, State}.
>
> Can I return {reply, {error, rejected}, State} immediately when I find that
> check_user return false? How can I write such code?
> I was a C++ programmer before, so expecting something like "return"
> keyword...
> Thanks! All of you give me great favor!
>


More information about the erlang-questions mailing list