Permalink
Browse files

start the dependency automatically

  • Loading branch information...
1 parent 2aa43a5 commit 95891b5d176e37d22206eeb14c9681334dd61db9 @haitaoyao committed Sep 15, 2012
Showing with 13 additions and 14 deletions.
  1. +13 −14 src/bigwig.erl
View
@@ -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.