Skip to content

Instantly share code, notes, and snippets.

@devonestes
Last active Feb 5, 2020
Embed
What would you like to do?
# 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