gen_server partial replies

Mikael Karlsson mikael.karlsson@REDACTED
Sun Nov 23 21:09:26 CET 2003


Sat 22 november 2003 23:48  Chandrashekhar Mullaparthi wrote:
> > -----Original Message-----
> > From: Mikael Karlsson [mailto:mikael.karlsson@REDACTED]
> > Sent: 22 November 2003 14:00
> > To: Bengt Kleberg; - Erlang Questions
> > Subject: Re: gen_server partial replies
> >
> > One thing in the gen_server code bothers me a bit though.
> > There is the main
> > loop function which calls the handle_msg function which calls
> > the loop
> > function and so on. Is this OK for an infinite process? Will
> > the compiler
> > handle the stack properly?
> >
> > loop(Parent, Name, State, Mod, Time, Debug) ->  ...
> >     handle_msg(Msg, Parent, Name, State, Mod, Time);
> >
> > handle_msg({'$gen_call', From, Msg}, Parent, Name, State,
> > Mod, _Time) ->
> >     case catch Mod:handle_call(Msg, From, State) of
> > 	{reply, Reply, NState} ->
> > 	    reply(From, Reply),
> > 	    loop(Parent, Name, NState, Mod, infinity, []);
> > ...
>
> The handle_msg and loop function are tail-recursive functions, so they wont
> cause the stack to grow. The compiler ensures that tail-recursive functions
> operate in constant stack space.
> ...

Thanks Chandru,
I wasn't sure this was valid for calls between functions as well.
/Mikael





More information about the erlang-questions mailing list