Skip to content

Instantly share code, notes, and snippets.

@petermueller
Last active August 3, 2022 00:27
Show Gist options
  • Save petermueller/8c2dbbfa61e577fafbab9329bd7b6355 to your computer and use it in GitHub Desktop.
Save petermueller/8c2dbbfa61e577fafbab9329bd7b6355 to your computer and use it in GitHub Desktop.
elixir OTP reminders
defmodule MyMod do
use GenServer
def child_spec(args) do
IO.inspect(args, label: "*** MyMod.child_spec/1")
%{
id: __MODULE__,
start: {__MODULE__, :start_link, [args]}
}
end
def start_link(args) do
IO.inspect(args, label: "*** MyMod.start_link/1")
GenServer.start_link(__MODULE__, args)
end
def init(args) do
IO.inspect(args, label: "*** MyMod.init/1")
{:ok, args}
end
end
# {:ok, sup_pid} = Supervisor.start_link([MyMod], name: MySup, strategy: :one_for_one)
{:ok, sup_pid} = Supervisor.start_link([{MyMod, test: :value}], name: MySup, strategy: :one_for_one)
Supervisor.stop(sup_pid)
# *** MyMod.child_spec/1: [test: :value]
# *** MyMod.start_link/1: [test: :value]
# *** MyMod.init/1: [test: :value]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment