From cfd924076c91906ef13017ff212d0ba88fcefff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Tue, 5 Mar 2013 15:53:10 +0100 Subject: 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', ...}}. --- lib/kernel/src/application.erl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib/kernel') 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) -> -- cgit v1.2.3