Skip to content

Instantly share code, notes, and snippets.

@devonestes
Last active February 5, 2020 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devonestes/7cb776124fb066b4405f1147e5ea6635 to your computer and use it in GitHub Desktop.
Save devonestes/7cb776124fb066b4405f1147e5ea6635 to your computer and use it in GitHub Desktop.
# My GenServer
defmodule My.GenServer do
def start_link() do
GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
end
def init(_) do
{:ok, []}
end
end
# My application.ex
defmodule My.Application do
use Application
def start(_, _) do
import Supervisor.Spec
children = [worker(My.GenServer, [])]
opts = [strategy: :one_for_one, name: My.Supervisor]
test_start(My.GenServer)
Supervisor.start_link(children, opts)
end
def test_start(module) do
module.start_link()
end
end
# Code I ran to inspect the xref graph
Mix.Tasks.Xref.calls()
|> Enum.filter(fn
%{callee: {_, :start_link, _}} -> true
_ -> false
end)
# Outputs
[
%{
callee: {Supervisor, :start_link, 2},
caller_module: My.Application,
file: "lib/my/application.ex",
line: 11
},
%{
callee: {GenServer, :start_link, 3},
caller_module: My.GenServer,
file: "lib/my/gen_server.ex",
line: 3
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment