Last active
July 23, 2017 08:31
-
-
Save ray-sh/7cbb39820c5d5113c102bb0d67d50779 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Demo how to create supervised pool worker | |
defmodule SupPoolWorker do | |
@moduledoc false | |
use Supervisor | |
def start_link(name,number) do | |
Supervisor.start_link(SupPoolWorker,number,name: name) | |
end | |
def init(number) do | |
children = for i <- 1..number, do: worker(DBWorker,[String.to_atom("Worker#{i}")], id: String.to_atom("Worker#{i}")) | |
supervise(children, strategy: :one_for_one) | |
end | |
end | |
defmodule DBWorker do | |
@moduledoc false | |
use GenServer | |
def start_link(name) do | |
IO.puts "worker #{name} start" | |
GenServer.start_link(DBWorker,name: name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment