[erlang-questions] time consuming operations inside gen_server
Roman Gafiyatullin
r.gafiyatullin@REDACTED
Wed Dec 12 10:58:00 CET 2012
Hello Martin,
In this cases the problem is usually solved as Attila Rajmund Nohl said.
Since it's the common situation I wrote a lib for that: https://github.com/RGafiyatullin/gen_wp
See src/gen_wp_example.erl (https://github.com/RGafiyatullin/gen_wp/blob/master/src/gen_wp_example.erl) for how to use it.
Questions and constructive critics are welcome and appreciated.
--
RG
On Wednesday, December 12, 2012 at 12:46 pm, Martin Dimitrov wrote:
> Thanks, this sounds very cool.
>
> On 12/12/2012 11:42 AM, Attila Rajmund Nohl wrote:
> > 2012/12/12 Martin Dimitrov <mrtndimitrov@REDACTED (mailto:mrtndimitrov@REDACTED)>:
> > > Hi all,
> > >
> > > In our application, we have a gen_server that does a time consuming
> > > operation. The message is of type cast thus the caller process doesn't
> > > sit and wait for the operation to finish. But while the gen_server is
> > > busy with the cast message, it doesn't serve any other call, right?
> > >
> > > So, would it be appropriate to create a process that will do the time
> > > consuming operation and then notify the gen_server?
> > >
> >
> >
> > The pattern I use in this case is to still use gen_server:call (if the
> > caller needs to be blocked), start a separate process for the
> > time-consuming stuff, return {noreply, ...} from the handle_call (so
> > the gen_server can handle other calls), then call gen_server:reply
> > from the started process when the time-consuming operation finished.
> > Of course, the applicability of this pattern depends on what you
> > actually do.
> >
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED (mailto:erlang-questions@REDACTED)
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121212/5deb144c/attachment.htm>
More information about the erlang-questions
mailing list