gen_server -- newbie code critique?

Torbjorn Tornkvist tobbe@REDACTED
Sun May 28 18:29:03 CEST 2006


Andrew Lentvorski wrote:
> I'm trying to understand the gen_server behaviors, but I really seem to
> be having some trouble.  So, what I tried to do was just create a
> wrapper around a basic queue that could be accessed by multiple
> processes.
> 
> It seems to do what I want, but I could certainly use some
> critque at this point.

Looks fine to me!
See a minor comment below.

> 
> Thanks,
> -a
> 
> -module(msqueue).
> -behaviour(gen_server).
>
...snip....
> 
> handle_call({out}, _From, State) ->
>    QR = queue:out(State#state.theQueue),
>    RR = case QR of

I would have written:

RR = case queue:out(State#state.theQueue) of

>          {{value, Item}, QQ} ->
>          {value, Item};
>          {empty, QQ} ->
>          {empty}
>      end,
>    {reply, RR, #state{theQueue=QQ}}.
> 

Cheers, Tobbe




More information about the erlang-questions mailing list