Skip to content

Instantly share code, notes, and snippets.

@blackode
Created April 3, 2018 13:51
Show Gist options
  • Save blackode/ef56c1b4e58043c092eeabdfd23b4af7 to your computer and use it in GitHub Desktop.
Save blackode/ef56c1b4e58043c092eeabdfd23b4af7 to your computer and use it in GitHub Desktop.
a supervisor
defmodule Bank.Supervisor do
use Supervisor
def start_link(initial_balance) do
bank_supervisor = {:ok, sup} = Supervisor.start_link(__MODULE__, [initial_balance])
start_children(sup, initial_balance)
bank_supervisor
end
def start_children(sup, initial_balance) do
{:ok, cache_pid} =
Supervisor.start_child(sup, worker(Bank.Cache, [initial_balance]))
Supervisor.start_child(sup, worker(Bank, [cache_pid]))
end
def init(_) do
supervise([], strategy: :one_for_one)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment