[erlang-questions] Erlang way for process-as-library?

Sean Hinde sean.hinde@REDACTED
Mon Feb 5 23:59:32 CET 2007


On 5 Feb 2007, at 22:33, Robert Baruch wrote:

> Hi all,
>
> So I'm fooling around with writing a utility library, but to
> initialize the library takes a little bit of time, needing to read a
> few large files into memory. So my idea was to stick the
> functionality into a process, so that the library could be
> initialized once and then used by the application.
>
> I've added the gen_server behavior to the process. So now my question
> is, what's the Erlang way to start the process? Should I start it
> supervised, with a supervisor running somewhere explicitly, and
> require the user to know that they have to start up a supervisor?
> Should I start it unsupervised, checking in every call to the library
> whether the library is running, and if not, start it?

For something like this I would leave it up to the user of the  
utility library to decide how it must be started/supervised. Each  
project I have worked on has had a different way of managing such  
long lived standard servers - if you build in assumptions on how it  
must be started then you will cause issues somewhere down the line.

I recommend you just provide the standard gen_server start and  
start_link API.

For your own project I would either use the OTP supervisors to start  
the server during app startup, or make your own simple supervisor if  
you don't like the "escalating disaster" model of the standard one.

BR,
Sean






More information about the erlang-questions mailing list