diff options
author | Björn-Egil Dahlberg <[email protected]> | 2013-03-05 15:53:10 +0100 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2013-03-05 15:53:10 +0100 |
commit | cfd924076c91906ef13017ff212d0ba88fcefff1 (patch) | |
tree | 465170d1e382ca878e8c67fe776db5e9061117e4 /lib/kernel/src/application.erl | |
parent | 8183fcfb059794823a8289456d68b20a80d9a1b4 (diff) | |
download | otp-cfd924076c91906ef13017ff212d0ba88fcefff1.tar.gz otp-cfd924076c91906ef13017ff212d0ba88fcefff1.tar.bz2 otp-cfd924076c91906ef13017ff212d0ba88fcefff1.zip |
kernel: Add application:ensure_started/1,2
Similar to application:start/1,2 except it returns 'ok' on already
started applications instead of {'error', {'already_started', ...}}.
Diffstat (limited to 'lib/kernel/src/application.erl')
-rw-r--r-- | lib/kernel/src/application.erl | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/kernel/src/application.erl b/lib/kernel/src/application.erl index 6efc1b4499..5dd6b73857 100644 --- a/lib/kernel/src/application.erl +++ b/lib/kernel/src/application.erl @@ -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) -> |