1
1
defmodule Process do
2
2
@ moduledoc """
3
- This module provides convenience functions around processes and
4
- the process dictionary. In Erlang, most of these functions are
5
- auto-imported, but in Elixir they are grouped in a module for
6
- convenience. Notice that these functions, different from Erlang's,
7
- always return nil instead of undefined. You can use their Erlang
8
- version if you want the undefined value.
3
+ Conveniences for working with processes and the process dictionary.
4
+
5
+ Some of the functions in this module are inlined by the compiler,
6
+ similar to functions in the `Kernel` module. When such happens,
7
+ they are explicitly tagged as so.
9
8
"""
10
9
11
10
@ doc """
@@ -81,16 +80,18 @@ defmodule Process do
81
80
1) If pid is not trapping exits, pid will exit with the given reason;
82
81
83
82
2) If pid is trapping exits, the exit signal is transformed into a message
84
- {' EXIT' , from, reason} and delivered to the message queue of pid;
83
+ {: EXIT, from, reason} and delivered to the message queue of pid;
85
84
86
85
3) If reason is the atom `:normal`, pid will not exit. If it is trapping exits,
87
- the exit signal is transformed into a message {' EXIT' , from, :normal} and
86
+ the exit signal is transformed into a message {: EXIT, from, :normal} and
88
87
delivered to its message queue;
89
88
90
89
4) If reason is the atom `:kill`, that is if `exit(pid, :kill)` is called, an
91
90
untrappable exit signal is sent to pid which will unconditionally exit with
92
91
exit reason `:killed`.
93
92
93
+ Inlined by the compiler.
94
+
94
95
## Examples
95
96
96
97
Process.exit(pid, :kill)
@@ -112,6 +113,8 @@ defmodule Process do
112
113
@ doc """
113
114
Returns the pid of a new process started by the application of `fun`.
114
115
It behaves exactly the same as `Kernel.spawn/1`.
116
+
117
+ Inlined by the compiler.
115
118
"""
116
119
@ spec spawn ( ( ( ) -> any ) ) :: pid
117
120
def spawn ( fun ) do
@@ -129,6 +132,8 @@ defmodule Process do
129
132
130
133
It also accepts extra options, for the list of available options
131
134
check http://www.erlang.org/doc/man/erlang.html#spawn_opt-2
135
+
136
+ Inlined by the compiler.
132
137
"""
133
138
@ spec spawn ( ( ( ) -> any ) , spawn_opts ) :: pid | { pid , reference }
134
139
def spawn ( fun , opts ) do
@@ -141,6 +146,8 @@ defmodule Process do
141
146
scheduler queue and be run some time later.
142
147
143
148
It behaves exactly the same as the `Kernel.spawn/3` function.
149
+
150
+ Inlined by the compiler.
144
151
"""
145
152
@ spec spawn ( module , atom , [ any ] ) :: pid
146
153
def spawn ( mod , fun , args ) do
@@ -155,6 +162,7 @@ defmodule Process do
155
162
It also accepts extra options, for the list of available options
156
163
check http://www.erlang.org/doc/man/erlang.html#spawn_opt-4
157
164
165
+ Inlined by the compiler.
158
166
"""
159
167
@ spec spawn ( module , atom , [ any ] , spawn_opts ) :: pid | { pid , reference }
160
168
def spawn ( mod , fun , args , opts ) do
@@ -165,6 +173,8 @@ defmodule Process do
165
173
Returns the pid of a new process started by the application of `fun`.
166
174
A link is created between the calling process and the new
167
175
process, atomically.
176
+
177
+ Inlined by the compiler.
168
178
"""
169
179
@ spec spawn_link ( ( ( ) -> any ) ) :: pid
170
180
def spawn_link ( fun ) do
@@ -175,6 +185,8 @@ defmodule Process do
175
185
Returns the pid of a new process started by the application of
176
186
`module.function(args)`. A link is created between the calling process
177
187
and the new process, atomically. Otherwise works like spawn/3.
188
+
189
+ Inlined by the compiler.
178
190
"""
179
191
@ spec spawn_link ( module , atom , [ any ] ) :: pid
180
192
def spawn_link ( mod , fun , args ) do
@@ -184,6 +196,8 @@ defmodule Process do
184
196
@ doc """
185
197
Returns the pid of a new process started by the application of `fun`
186
198
and reference for a monitor created to the new process.
199
+
200
+ Inlined by the compiler.
187
201
"""
188
202
@ spec spawn_monitor ( ( ( ) -> any ) ) :: { pid , reference }
189
203
def spawn_monitor ( fun ) do
@@ -194,6 +208,8 @@ defmodule Process do
194
208
A new process is started by the application of `module.function(args)`
195
209
and the process is monitored at the same time. Returns the pid and a
196
210
reference for the monitor. Otherwise works like spawn/3.
211
+
212
+ Inlined by the compiler.
197
213
"""
198
214
@ spec spawn_monitor ( module , atom , [ any ] ) :: { pid , reference }
199
215
def spawn_monitor ( mod , fun , args ) do
@@ -205,6 +221,8 @@ defmodule Process do
205
221
It returns the monitor reference.
206
222
207
223
See http://www.erlang.org/doc/man/erlang.html#monitor-2 for more info.
224
+
225
+ Inlined by the compiler.
208
226
"""
209
227
@ spec monitor ( pid | { reg_name :: atom , node :: atom } | reg_name :: atom ) :: reference
210
228
def monitor ( item ) do
@@ -217,6 +235,8 @@ defmodule Process do
217
235
If the monitoring is already turned off, nothing happens.
218
236
219
237
See http://www.erlang.org/doc/man/erlang.html#demonitor-2 for more info.
238
+
239
+ Inlined by the compiler.
220
240
"""
221
241
@ spec demonitor ( reference ) :: true
222
242
@ spec demonitor ( reference , options :: [ :flush | :info ] ) :: boolean
@@ -244,6 +264,8 @@ defmodule Process do
244
264
(or port) `pid`, if there is not such a link already.
245
265
246
266
See http://www.erlang.org/doc/man/erlang.html#link-1 for more info.
267
+
268
+ Inlined by the compiler.
247
269
"""
248
270
@ spec link ( pid | port ) :: true
249
271
def link ( pid ) do
@@ -256,6 +278,8 @@ defmodule Process do
256
278
fail, even if there is no link or `id` does not exist
257
279
258
280
See http://www.erlang.org/doc/man/erlang.html#unlink-1 for more info.
281
+
282
+ Inlined by the compiler.
259
283
"""
260
284
@ spec unlink ( pid | port ) :: true
261
285
def unlink ( pid ) do
0 commit comments