-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose getting process dictionary value for specific key in Process.info/2 #13505
Changes from 1 commit
8e53a61
7c9e2dc
16ae690
0354937
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -826,6 +826,9 @@ defmodule Process do | |||||||||||||||||
@spec flag(pid, :save_calls, 0..10000) :: 0..10000 | ||||||||||||||||||
defdelegate flag(pid, flag, value), to: :erlang, as: :process_flag | ||||||||||||||||||
|
||||||||||||||||||
@type process_info_item :: atom | {:dictionary, term} | ||||||||||||||||||
@type process_info_result_item :: {process_info_item, term} | ||||||||||||||||||
|
||||||||||||||||||
@doc """ | ||||||||||||||||||
Returns information about the process identified by `pid`, or returns `nil` if the process | ||||||||||||||||||
is not alive. | ||||||||||||||||||
|
@@ -834,7 +837,7 @@ defmodule Process do | |||||||||||||||||
|
||||||||||||||||||
See `:erlang.process_info/1` for more information. | ||||||||||||||||||
""" | ||||||||||||||||||
@spec info(pid) :: keyword | nil | ||||||||||||||||||
@spec info(pid) :: [process_info_result_item] | nil | ||||||||||||||||||
def info(pid) do | ||||||||||||||||||
nilify(:erlang.process_info(pid)) | ||||||||||||||||||
end | ||||||||||||||||||
|
@@ -845,7 +848,8 @@ defmodule Process do | |||||||||||||||||
|
||||||||||||||||||
See `:erlang.process_info/2` for more information. | ||||||||||||||||||
""" | ||||||||||||||||||
@spec info(pid, atom | [atom]) :: {atom, term} | [{atom, term}] | nil | ||||||||||||||||||
@spec info(pid, process_info_item | [process_info_item]) :: | ||||||||||||||||||
process_info_result_item | [process_info_result_item] | nil | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think this could work as well and be better for documentation (althoguh maybe Dialyzer would unify these types internally?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pleasantly surprised to report that this improves the spec for Dialyzer as well:
and for
|
||||||||||||||||||
def info(pid, spec) | ||||||||||||||||||
|
||||||||||||||||||
def info(pid, :registered_name) do | ||||||||||||||||||
|
@@ -856,6 +860,10 @@ defmodule Process do | |||||||||||||||||
end | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
def info(pid, {:dictionary, key}) do | ||||||||||||||||||
nilify(:erlang.process_info(pid, {:dictionary, key})) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
def info(pid, spec) when is_atom(spec) or is_list(spec) do | ||||||||||||||||||
nilify(:erlang.process_info(pid, spec)) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would actually remove the specific clauses. Now that Erlang/OTP has good error messages, they will probably be more decent than function clause error?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Erlang 26.2.2 the error looks like:
|
||||||||||||||||||
end | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Maybe this one is too imprecise here? Since the key will always be an atom,
keyword
might be more accurate.Or should we refer
:erlang.process_info_result_item()
which is a bit more precise? But dialyzer would generalize toatom
anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this function can actually return individual dictionary keys? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points about this function clause, I will revert this change to info/1 spec
Unfortunately the type is not exported, Dialyzer says: