Last active
February 5, 2020 08:42
-
-
Save devonestes/7cb776124fb066b4405f1147e5ea6635 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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