@@ -3,13 +3,10 @@ defmodule Task.Supervisor do
33 A task supervisor.
44
55 This module defines a supervisor which can be used to dynamically
6- supervise tasks. Behind the scenes, this module is implemented as a
7- `:simple_one_for_one` supervisor where the workers are temporary by
8- default (that is, they are not restarted after they die; read the docs
9- for `start_link/1` for more information on choosing the restart
10- strategy).
6+ supervise tasks.
117
12- See the `Task` module for more information.
8+ `start_link/1` can be used to start the supervisor. See the `Task`
9+ module for more examples.
1310
1411 ## Name registration
1512
@@ -36,19 +33,23 @@ defmodule Task.Supervisor do
3633
3734 The supported options are:
3835
39- * `:name` - used to register a supervisor name, the supported values are
40- described under the `Name Registration` section in the `GenServer` module
41- docs;
36+ * `:name` - used to register a supervisor name, the supported values are
37+ described under the `Name Registration` section in the `GenServer` module
38+ docs;
4239
43- * `:restart` - the restart strategy, may be `:temporary` (the default),
44- `:transient` or `:permanent`. Check `Supervisor` for more info.
45- Defaults to `:temporary` so tasks aren't automatically restarted when
46- they complete nor in case of crashes;
40+ * `:restart` - the restart strategy, may be `:temporary` (the default),
41+ `:transient` or `:permanent`. `:temporary` means the task is never
42+ restarted, `:transient` means it is restarted if the exit is not
43+ `:normal`, `:shutdown` or `{:shutdown, reason}`. A `:permanent` restart
44+ strategy means it is always restarted. It defaults to `:temporary` so
45+ tasks aren't automatically restarted when they complete nor in case of
46+ crashes. Note the `:async` functions in this module support only `:temporary`
47+ restarts;
4748
48- * `:shutdown` - `:brutal_kill` if the tasks must be killed directly on shutdown
49- or an integer indicating the timeout value, defaults to 5000 milliseconds;
49+ * `:shutdown` - `:brutal_kill` if the tasks must be killed directly on shutdown
50+ or an integer indicating the timeout value, defaults to 5000 milliseconds;
5051
51- * `:max_restarts` and `:max_seconds` - as specified in `Supervisor`;
52+ * `:max_restarts` and `:max_seconds` - as specified in `Supervisor`;
5253
5354 """
5455 @ spec start_link ( [ option ] ) :: Supervisor . on_start
@@ -70,6 +71,10 @@ defmodule Task.Supervisor do
7071 The `supervisor` must be a reference as defined in `Task.Supervisor`.
7172 The task will still be linked to the caller, see `Task.async/3` for
7273 more information and `async_nolink/2` for a non-linked variant.
74+
75+ Note this function requires the task supervisor to have `:temporary`
76+ as the `:restart` option (the default), as `async/2` keeps a direct
77+ reference to the task which is lost if the task is restarted.
7378 """
7479 @ spec async ( Supervisor . supervisor , ( ( ) -> any ) ) :: Task . t
7580 def async ( supervisor , fun ) do
@@ -82,6 +87,10 @@ defmodule Task.Supervisor do
8287 The `supervisor` must be a reference as defined in `Task.Supervisor`.
8388 The task will still be linked to the caller, see `Task.async/3` for
8489 more information and `async_nolink/2` for a non-linked variant.
90+
91+ Note this function requires the task supervisor to have `:temporary`
92+ as the `:restart` option (the default), as `async/4` keeps a direct
93+ reference to the task which is lost if the task is restarted.
8594 """
8695 @ spec async ( Supervisor . supervisor , module , atom , [ term ] ) :: Task . t
8796 def async ( supervisor , module , fun , args ) do
@@ -95,6 +104,10 @@ defmodule Task.Supervisor do
95104 The task won't be linked to the caller, see `Task.async/3` for
96105 more information.
97106
107+ Note this function requires the task supervisor to have `:temporary`
108+ as the `:restart` option (the default), as `async_nolink/2` keeps a
109+ direct reference to the task which is lost if the task is restarted.
110+
98111 ## Compatibility with OTP behaviours
99112
100113 If you create a task using `async_nolink` inside an OTP behaviour
@@ -121,6 +134,10 @@ defmodule Task.Supervisor do
121134 The `supervisor` must be a reference as defined in `Task.Supervisor`.
122135 The task won't be linked to the caller, see `Task.async/3` for
123136 more information.
137+
138+ Note this function requires the task supervisor to have `:temporary`
139+ as the `:restart` option (the default), as `async_nolink/4` keeps a
140+ direct reference to the task which is lost if the task is restarted.
124141 """
125142 @ spec async_nolink ( Supervisor . supervisor , module , atom , [ term ] ) :: Task . t
126143 def async_nolink ( supervisor , module , fun , args ) do
@@ -145,6 +162,10 @@ defmodule Task.Supervisor do
145162 can also be given as an option representing the maximum amount of
146163 time to wait without a task reply.
147164
165+ Note this function requires the task supervisor to have `:temporary`
166+ as the `:restart` option (the default), as `async_stream/6` keeps a
167+ direct reference to the task which is lost if the task is restarted.
168+
148169 Finally, if you find yourself trapping exits to handle exits inside
149170 the async stream, consider using `async_stream_nolink/6` to start tasks
150171 that are not linked to the current process.
0 commit comments