Permalink
Browse files

Merge branch 'egil/kernel/application-ensure_started/OTP-10910' into …

…maint

* egil/kernel/application-ensure_started/OTP-10910:
  kernel: Document application:ensure_started/1,2
  tests: Refactor away ?line macro in test suite
  kernel: Tests for application:ensure_started/1,2
  kernel: Add application:ensure_started/1,2
  • Loading branch information...
2 parents 6e44549 + 7bfa194 commit 4955bf98ead49b0c7122ab30e462f9b817bd5c6e @psyeugenic psyeugenic committed Mar 12, 2013
Showing with 816 additions and 759 deletions.
  1. +9 −0 lib/kernel/doc/src/application.xml
  2. +23 −0 lib/kernel/src/application.erl
  3. +784 −759 lib/kernel/test/application_SUITE.erl
@@ -253,6 +253,15 @@ Nodes = [cp1@cave, {cp2@cave, cp3@cave}]</code>
</warning>
</desc>
</func>
+ <func>
+ <name name="ensure_started" arity="1"/>
+ <name name="ensure_started" arity="2"/>
+ <fsummary>Load and start an application</fsummary>
+ <desc>
+ <p>Equivalent to <seealso marker="#start/2"><c>application:start/1,2</c></seealso> except
+ it returns <c>ok</c> for already started applications.</p>
+ </desc>
+ </func>
<func>
<name name="start" arity="1"/>
<name name="start" arity="2"/>
@@ -22,6 +22,7 @@
load/1, load/2, unload/1, takeover/2,
which_applications/0, which_applications/1,
loaded_applications/0, permit/2]).
+-export([ensure_started/1, ensure_started/2]).
-export([set_env/3, set_env/4, unset_env/2, unset_env/3]).
-export([get_env/1, get_env/2, get_env/3, get_all_env/0, get_all_env/1]).
-export([get_key/1, get_key/2, get_all_key/0, get_all_key/1]).
@@ -135,6 +136,28 @@ start(Application, RestartType) ->
Error
end.
+-spec ensure_started(Application) -> 'ok' | {'error', Reason} when
+ Application :: atom(),
+ Reason :: term().
+
+ensure_started(Application) ->
+ ensure_started(Application, temporary).
+
+-spec ensure_started(Application, Type) -> 'ok' | {'error', Reason} when
+ Application :: atom(),
+ Type :: restart_type(),
+ Reason :: term().
+
+ensure_started(Application, RestartType) ->
+ case start(Application, RestartType) of
+ ok ->
+ ok;
+ {error, {already_started, Application}} ->
+ ok;
+ Error ->
+ Error
+ end.
+
-spec start_boot(Application :: atom()) -> 'ok' | {'error', term()}.
start_boot(Application) ->
Oops, something went wrong.

0 comments on commit 4955bf9

Please sign in to comment.