[erlang-questions] initializing library applications without processes

Garrett Smith <>
Sun Apr 4 01:58:53 CEST 2010


On Sat, Apr 3, 2010 at 12:41 PM, Ulf Wiger
<> wrote:
>
> I received exactly this question while at the SF Erlang Factory.
>
> My suggestion is: start a supervisor with no children. A reasonable
> "cheat" is to put all of this in the app file
>
> -module(myapp).
> -behaviour(application).
> -export([start/2, stop/1]).
> -behaviour(supervisor).
> -export([init/1]).
>
> start(_, _) ->
>   supervisor:start_link({local,?MODULE},?MODULE,[]).
>
> stop(_) -> ok.
>
> init([]) ->
>   %% create tables here...
>   {ok, {{one_for_one,3,10},[]}}.

The docs say you can return 'ignore' here as well. I've never tried
that, but it might give this hack even more panache, assuming it
doesn't implicitly terminate the process :)

Garrett


More information about the erlang-questions mailing list