Skip to content

Commit 88ef005

Browse files
eksperimentaljosevalim
authored andcommitted
Improve docs and type for Kernel.send/2 & Process.send/3 (#7862)
Kernel.send/2: - Simplify/Improve description of `dest` Process.send/3: - Refer to `dest` and not just "process" - Duplicate definition of `dest` in Process.send/3
1 parent 2583b1d commit 88ef005

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,9 @@ defmodule Kernel do
797797
@doc """
798798
Sends a message to the given `dest` and returns the message.
799799
800-
`dest` may be a remote or local PID, a (local) port, a locally
801-
registered name, or a tuple `{registered_name, node}` for a registered
802-
name at another node.
800+
`dest` may be a remote or local PID, a local port, a locally
801+
registered name, or a tuple in the form of `{registered_name, node}` for a
802+
registered name at another node.
803803
804804
Inlined by the compiler.
805805
@@ -809,7 +809,7 @@ defmodule Kernel do
809809
:hello
810810
811811
"""
812-
@spec send(dest :: pid | port | atom | {atom, node}, message) :: message when message: any
812+
@spec send(dest :: Process.dest(), message) :: message when message: any
813813
def send(dest, message) do
814814
:erlang.send(dest, message)
815815
end

lib/elixir/lib/process.ex

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ defmodule Process do
3030
3131
Inlined by the compiler.
3232
"""
33+
34+
@typedoc """
35+
A process destination.
36+
37+
A remote or local PID, a local port, a locally registered name, or a tuple in
38+
the form of `{registered_name, node}` for a registered name at another node.
39+
"""
40+
@type dest :: pid | port | registered_name :: atom | {registered_name :: atom, node}
41+
3342
@spec alive?(pid) :: boolean
3443
defdelegate alive?(pid), to: :erlang, as: :is_process_alive
3544

@@ -220,7 +229,11 @@ defmodule Process do
220229
end
221230

222231
@doc """
223-
Sends a message to the given process.
232+
Sends a message to the given `dest`.
233+
234+
`dest` may be a remote or local PID, a local port, a locally
235+
registered name, or a tuple in the form of `{registered_name, node}` for a
236+
registered name at another node.
224237
225238
Inlined by the compiler.
226239
@@ -242,7 +255,7 @@ defmodule Process do
242255
243256
"""
244257
@spec send(dest, msg, [option]) :: :ok | :noconnect | :nosuspend
245-
when dest: pid | port | atom | {atom, node},
258+
when dest: dest(),
246259
msg: any,
247260
option: :noconnect | :nosuspend
248261
defdelegate send(dest, msg, options), to: :erlang
@@ -395,7 +408,7 @@ defmodule Process do
395408
* `object` is either a `pid` of the monitored process (if monitoring
396409
a PID) or `{name, node}` (if monitoring a remote or local name);
397410
* `reason` is the exit reason.
398-
411+
399412
If the process is already dead when calling `Process.monitor/1`, a
400413
`:DOWN` message is delivered immediately.
401414

0 commit comments

Comments
 (0)