Last active
February 5, 2018 05:52
-
-
Save LukeWood/1832a19baf643d4b73608660909b5069 to your computer and use it in GitHub Desktop.
Basic module that supports dynamically attached supervised children in elixir
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 Dynamic do | |
defdelegate start_link(), to: Dynamic.Server | |
defdelegate new, to: Dynamic.Supervisor | |
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 Dynamic.Server do | |
use GenServer | |
def start_link() do | |
GenServer.start_link(__MODULE__, %{}) | |
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 Dynamic.Supervisor do | |
use Supervisor | |
def start(_opts, _args) do | |
Supervisor.start_link(__MODULE__, :ok, name: __MODULE__) | |
end | |
def init(:ok) do | |
children =[ | |
worker(Bullet.Server, [], restart: :temporary) | |
] | |
opts = [ | |
strategy: :simple_one_for_one | |
] | |
supervise(children, opts) | |
end | |
# End use api | |
def new do | |
Supervisor.start_child(__MODULE__, []) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment