Skip to content

Instantly share code, notes, and snippets.

@TylerPachal
Created November 10, 2021 12:32
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 TylerPachal/9a7291fb9ba1c4bc8dcfdb39a6020cd6 to your computer and use it in GitHub Desktop.
Save TylerPachal/9a7291fb9ba1c4bc8dcfdb39a6020cd6 to your computer and use it in GitHub Desktop.
# Without specifying a child_spec, you get the default one:
# default = %{
# id: __MODULE__,
# start: {__MODULE__, :start_link, [init_arg]}
# }
# A: calls start_link/1 with empty list of args
# children = [
# DevWorker
# ]
#
# "start_link/1"
# []
# B: Calls start_link/1 with single arg
# children = [
# {DevWorker, :foo}
# ]
#
# "start_link/1"
# :foo
# C: Calls start_link/1 with the same list of args
# children = [
# {DevWorker, [:foo, :bar]}
# ]
#
# "start_link/1"
# [:foo, :bar]
# With a custom child_spec:
#
# def child_spec([a, b]) do
# %{
# id: make_ref(),
# start: {__MODULE__, :start_link, [a, b]}
# }
# end
#
# children = [
# {DevWorker, [:foo, :bar]}
# ]
#
# "start_link/2"
# :foo
# :bar
def child_spec([a, b]) do
%{
id: make_ref(),
start: {__MODULE__, :start_link, [a, b]}
}
end
def start_link(a) do
IO.inspect("start_link/1")
IO.inspect(a)
end
def start_link(a, b) do
IO.inspect("start_link/2")
IO.inspect(a)
IO.inspect(b)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment