@@ -3,13 +3,10 @@ defmodule Task.Supervisor do
3
3
A task supervisor.
4
4
5
5
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.
11
7
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.
13
10
14
11
## Name registration
15
12
@@ -36,19 +33,23 @@ defmodule Task.Supervisor do
36
33
37
34
The supported options are:
38
35
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;
42
39
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;
47
48
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;
50
51
51
- * `:max_restarts` and `:max_seconds` - as specified in `Supervisor`;
52
+ * `:max_restarts` and `:max_seconds` - as specified in `Supervisor`;
52
53
53
54
"""
54
55
@ spec start_link ( [ option ] ) :: Supervisor . on_start
@@ -70,6 +71,10 @@ defmodule Task.Supervisor do
70
71
The `supervisor` must be a reference as defined in `Task.Supervisor`.
71
72
The task will still be linked to the caller, see `Task.async/3` for
72
73
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.
73
78
"""
74
79
@ spec async ( Supervisor . supervisor , ( ( ) -> any ) ) :: Task . t
75
80
def async ( supervisor , fun ) do
@@ -82,6 +87,10 @@ defmodule Task.Supervisor do
82
87
The `supervisor` must be a reference as defined in `Task.Supervisor`.
83
88
The task will still be linked to the caller, see `Task.async/3` for
84
89
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.
85
94
"""
86
95
@ spec async ( Supervisor . supervisor , module , atom , [ term ] ) :: Task . t
87
96
def async ( supervisor , module , fun , args ) do
@@ -95,6 +104,10 @@ defmodule Task.Supervisor do
95
104
The task won't be linked to the caller, see `Task.async/3` for
96
105
more information.
97
106
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
+
98
111
## Compatibility with OTP behaviours
99
112
100
113
If you create a task using `async_nolink` inside an OTP behaviour
@@ -121,6 +134,10 @@ defmodule Task.Supervisor do
121
134
The `supervisor` must be a reference as defined in `Task.Supervisor`.
122
135
The task won't be linked to the caller, see `Task.async/3` for
123
136
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.
124
141
"""
125
142
@ spec async_nolink ( Supervisor . supervisor , module , atom , [ term ] ) :: Task . t
126
143
def async_nolink ( supervisor , module , fun , args ) do
@@ -145,6 +162,10 @@ defmodule Task.Supervisor do
145
162
can also be given as an option representing the maximum amount of
146
163
time to wait without a task reply.
147
164
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
+
148
169
Finally, if you find yourself trapping exits to handle exits inside
149
170
the async stream, consider using `async_stream_nolink/6` to start tasks
150
171
that are not linked to the current process.
0 commit comments