Created
October 24, 2016 12:23
-
-
Save sergio1990/738d5fc7675535c7c217a1a317389c39 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
defmodule DynamicProcesses do | |
use Application | |
def start(_type, _args) do | |
import Supervisor.Spec, warn: false | |
children = [ | |
] | |
opts = [strategy: :one_for_one, name: DynamicProcesses.Supervisor] | |
Supervisor.start_link(children, opts) | |
end | |
end |
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
defmodule DynamicProcesses.Examples do | |
alias DynamicProcesses.SomeSupervisor | |
import Supervisor.Spec | |
def add_single_supervisor(id \\ "1") do | |
{:ok, supervisor_spec} = build_supervisor_spec(SomeSupervisor, [], id) | |
Supervisor.start_child(DynamicProcesses.Supervisor, supervisor_spec) | |
end | |
defp build_supervisor_spec(module, args, id) do | |
supervisor_spec = supervisor(module, args, [id: "supervisor" <> id]) | |
{:ok, supervisor_spec} | |
end | |
end |
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
defmodule DynamicProcesses.SomeSupervisor do | |
use Supervisor | |
def start_link do | |
Supervisor.start_link(__MODULE__, []) | |
end | |
def init([]) do | |
children = [] | |
supervise(children, strategy: :one_for_all) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment