Skip to content

Commit

Permalink
Changed the ok = application:start(app) to ignore errors if the appli…
Browse files Browse the repository at this point in the history
…cation was already started.
  • Loading branch information
nisbus committed Dec 30, 2012
1 parent 5278dba commit 38fcfa9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/ezwebframe.erl
Expand Up @@ -9,7 +9,8 @@
websocket_info/3,
append_div/3,
pre/1,
fill_div/3
fill_div/3,
start_if_not_running/1
]).

-import(ezwebframe_mochijson2, [encode/1, decode/1]).
Expand All @@ -20,8 +21,8 @@
-record(env, {dispatch}).

start_embedded(Port) ->
ok = application:start(ranch),
ok = application:start(cowboy),
ok = start_if_not_running(ranch),
ok = start_if_not_running(cowboy),
web_server_start(Port, "zip"),
receive
after
Expand All @@ -36,9 +37,9 @@ start_link([PortAtom, DirAtom]) ->
start_link(Dir, Port).

start_link(Dispatch, Port) ->
ok = application:start(crypto),
ok = application:start(ranch),
ok = application:start(cowboy),
ok = start_if_not_running(crypto),
ok = start_if_not_running(ranch),
ok = start_if_not_running(cowboy),
ok = web_server_start(Port, Dispatch),
receive
after
Expand Down Expand Up @@ -263,6 +264,11 @@ atomize(L) when is_list(L) ->
atomize(X) ->
X.

start_if_not_running(App) ->
case application:get_application(App) of
{ok, App} -> ok;
undefined -> application:start(App)
end.
%%----------------------------------------------------------------------
%% these are to be called from the gui client code

Expand Down

0 comments on commit 38fcfa9

Please sign in to comment.