Skip to content

Commit

Permalink
start the dependency automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
haitaoyao committed Sep 15, 2012
1 parent 2aa43a5 commit 95891b5
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/bigwig.erl
@@ -1,20 +1,19 @@
-module(bigwig).
-export([start/0, stop/0]).

ensure_started(App) ->
case application:start(App) of
ok ->
ok;
{error, {already_started, App}} ->
ok
end.

start() ->
ensure_started(crypto),
ensure_started(sasl),
ensure_started(cowboy),
ensure_started(jsx),
application:start(bigwig).

start(bigwig).
stop() ->
application:stop(bigwig).
start(App) ->
start_ok(App, application:start(App, permanent)).

start_ok(_App, ok) ->
ok;
start_ok(_App, {error, {already_started, _App}}) ->
ok;
start_ok(App, {error, {not_started, Dep}}) ->
ok = start(Dep),
start(App);
start_ok(_App, {error, Reason}) ->
erlang:error({app_start_failed, Reason}).

0 comments on commit 95891b5

Please sign in to comment.