@@ -429,6 +429,28 @@ defmodule Application do
429
429
@ type value :: term
430
430
@ type state :: term
431
431
@ type start_type :: :normal | { :takeover , node } | { :failover , node }
432
+
433
+ @ typedoc """
434
+ Specifies the type of the application:
435
+
436
+ * `:permanent` - if `app` terminates, all other applications and the entire
437
+ node are also terminated.
438
+
439
+ * `:transient` - if `app` terminates with `:normal` reason, it is reported
440
+ but no other applications are terminated. If a transient application
441
+ terminates abnormally, all other applications and the entire node are
442
+ also terminated.
443
+
444
+ * `:temporary` - if `app` terminates, it is reported but no other
445
+ applications are terminated (the default).
446
+
447
+ Note that it is always possible to stop an application explicitly by calling
448
+ `stop/1`. Regardless of the type of the application, no other applications will
449
+ be affected.
450
+
451
+ Note also that the `:transient` type is of little practical use, since when a
452
+ supervision tree terminates, the reason is set to `:shutdown`, not `:normal`.
453
+ """
432
454
@ type restart_type :: :permanent | :transient | :temporary
433
455
434
456
@ doc """
@@ -823,30 +845,16 @@ defmodule Application do
823
845
end
824
846
825
847
@ doc """
826
- Ensures the given `app` is started.
848
+ Ensures the given `app` is started with `t:restart_type/0` .
827
849
828
850
Same as `start/2` but returns `:ok` if the application was already
829
851
started.
830
-
831
- ## Options
832
-
833
- * `:type` - if the application should be started in `:permanent`,
834
- `:temporary`, or `:transient`. See `start/2` for more information.
835
-
836
852
"""
837
- @ spec ensure_started ( app , type: restart_type ( ) ) :: :ok | { :error , term }
838
- def ensure_started ( app , opts \\ [ ] )
839
-
840
- def ensure_started ( app , type ) when is_atom ( app ) and is_atom ( type ) do
841
- # TODO: Deprecate me on Elixir v1.19
853
+ @ spec ensure_started ( app , restart_type ( ) ) :: :ok | { :error , term }
854
+ def ensure_started ( app , type \\ :temporary ) when is_atom ( app ) and is_atom ( type ) do
842
855
:application . ensure_started ( app , type )
843
856
end
844
857
845
- def ensure_started ( app , opts ) when is_atom ( app ) and is_list ( opts ) do
846
- opts = Keyword . validate! ( opts , type: :temporary )
847
- :application . ensure_started ( app , opts [ :type ] )
848
- end
849
-
850
858
@ doc """
851
859
Ensures the given `app` is loaded.
852
860
@@ -866,21 +874,25 @@ defmodule Application do
866
874
@ doc """
867
875
Ensures the given `app` or `apps` and their child applications are started.
868
876
877
+ The second argument is either the `t:restart_type/1` (for consistency with
878
+ `start/2`) or a keyword list.
879
+
869
880
## Options
870
881
871
882
* `:type` - if the application should be started in `:permanent`,
872
- `:temporary`, or `:transient`. See `start/2 ` for more information.
883
+ `:temporary`, or `:transient`. See `t:restart_type/1 ` for more information.
873
884
874
885
* `:mode` - (since v1.15.0) if the applications should be started serially
875
886
or concurrently. This option requires Erlang/OTP 26+.
876
887
877
888
"""
878
889
@ spec ensure_all_started ( app | [ app ] , type: restart_type ( ) , mode: :serial | :concurrent ) ::
879
890
{ :ok , [ app ] } | { :error , term }
880
- def ensure_all_started ( app_or_apps , opts \\ [ ] )
891
+ @ spec ensure_all_started ( app | [ app ] , restart_type ( ) ) ::
892
+ { :ok , [ app ] } | { :error , term }
893
+ def ensure_all_started ( app_or_apps , type_or_opts \\ [ ] )
881
894
882
895
def ensure_all_started ( app , type ) when is_atom ( type ) do
883
- # TODO: Deprecate me on Elixir v1.19
884
896
ensure_all_started ( app , type: type )
885
897
end
886
898
@@ -907,7 +919,7 @@ defmodule Application do
907
919
end
908
920
909
921
@ doc """
910
- Starts the given `app`.
922
+ Starts the given `app` with `t:restart_type/0` .
911
923
912
924
If the `app` is not loaded, the application will first be loaded using `load/1`.
913
925
Any included application, defined in the `:included_applications` key of the
@@ -919,42 +931,12 @@ defmodule Application do
919
931
920
932
In case you want to automatically load **and start** all of `app`'s dependencies,
921
933
see `ensure_all_started/2`.
922
-
923
- ## Options
924
-
925
- * `:type` - specifies the type of the application:
926
-
927
- * `:permanent` - if `app` terminates, all other applications and the entire
928
- node are also terminated.
929
-
930
- * `:transient` - if `app` terminates with `:normal` reason, it is reported
931
- but no other applications are terminated. If a transient application
932
- terminates abnormally, all other applications and the entire node are
933
- also terminated.
934
-
935
- * `:temporary` - if `app` terminates, it is reported but no other
936
- applications are terminated (the default).
937
-
938
- Note that it is always possible to stop an application explicitly by calling
939
- `stop/1`. Regardless of the type of the application, no other applications will
940
- be affected.
941
-
942
- Note also that the `:transient` type is of little practical use, since when a
943
- supervision tree terminates, the reason is set to `:shutdown`, not `:normal`.
944
934
"""
945
- @ spec start ( app , type: restart_type ( ) ) :: :ok | { :error , term }
946
- def start ( app , opts \\ [ ] )
947
-
948
- def start ( app , type ) when is_atom ( app ) and is_atom ( type ) do
949
- # TODO: Deprecate me on Elixir v1.19
935
+ @ spec start ( app , restart_type ( ) ) :: :ok | { :error , term }
936
+ def start ( app , type \\ :temporary ) when is_atom ( app ) and is_atom ( type ) do
950
937
:application . start ( app , type )
951
938
end
952
939
953
- def start ( app , opts ) when is_atom ( app ) and is_list ( opts ) do
954
- opts = Keyword . validate! ( opts , type: :temporary )
955
- :application . start ( app , opts [ :type ] )
956
- end
957
-
958
940
@ doc """
959
941
Stops the given `app`.
960
942
0 commit comments