Skip to content

Instantly share code, notes, and snippets.

@petermueller
Last active August 3, 2022 00:27
Show Gist options
  • Select an option

  • Save petermueller/8c2dbbfa61e577fafbab9329bd7b6355 to your computer and use it in GitHub Desktop.

Select an option

Save petermueller/8c2dbbfa61e577fafbab9329bd7b6355 to your computer and use it in GitHub Desktop.

Revisions

  1. @felix-starman felix-starman revised this gist Jun 23, 2020. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions supervision_with_child_spec.exs
    Original file line number Diff line number Diff line change
    @@ -23,3 +23,7 @@ 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]
  2. @felix-starman felix-starman created this gist May 18, 2020.
    25 changes: 25 additions & 0 deletions supervision_with_child_spec.exs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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)