gen_server
Vlad Dumitrescu
vlad_dumitrescu@REDACTED
Tue Dec 16 13:29:52 CET 2003
From: "Sean Hinde" <sean.hinde@REDACTED>
> Alternatively, and what I normally do, is to store the From ref and the
> Pid of the spawned process in an ets table owned by the main gen_server
> process. The worker process then casts the answer back via the main
> gen_server process which does the gen_server:reply/2. This way if the
> worker process crashes the main gen_server can trap the 'EXIT' message,
> lookup the Pid/From, and send an error response back to the original
> caller.
>
> I think perhaps gen_server:reply needs to be added to the FAQ, or maybe
> a chapter devoted to this model somewhere in the docs - I have had to
> explain it many times and it is far too useful to not have prominence.
Just a thought: from my experience this pattern is used quite a lot, so it might
be useful to incorporate it in the basic gen_server. For example, one could use
gen_server:spawn_worker that will also handle the bookkeeping and also handle
worker exits behind the scenes. Some hooks can be provided for customization.
Would it be wrth the trouble?
regards,
/Vlad
More information about the erlang-questions
mailing list