Instead of using a custom implementation to get the state of a process:
defmodule MyModule do
use GenServer
def report(server) do
GenServer.call(server, :report)
end
# More functions
@impl true
def handle_call(:report, _from, state) do
# No modifications. Return the current state
{:reply, state, state}
end
endThis is all you need to do instead
{:ok, pid} = MyModule.start_link([])
# ... some more operations...
:sys.get_state(pid)Well, it does say right there in the get_state docs that the whole purpose is to help the users not to reimplement it.
Now I know and so do you 😀
More resources:
https://hexdocs.pm/elixir/GenServer.html#module-debugging-with-the-sys-module