Created
September 7, 2018 14:34
-
-
Save deque-blog/f4be2aacf6ec3a82f129e15ecda6f36a 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
defmodule Pool do | |
def start_link(poolName, %{worker_module: worker_module, size: size}) do | |
pool_config = [ | |
{:name, {:local, poolName}}, | |
{:worker_module, worker_module}, | |
{:size, size}, | |
{:max_overflow, 0} | |
] | |
children = [ :poolboy.child_spec(poolName, pool_config) ] | |
Supervisor.start_link(children, [strategy: :one_for_one]) | |
end | |
def stop(this) do | |
Supervisor.stop(this) | |
end | |
def call(poolName, message) do | |
call(poolName, message, 60000) | |
end | |
def call(poolName, message, timeout) do | |
Task.async(fn -> | |
:poolboy.transaction( | |
poolName, | |
fn pid -> GenServer.call(pid, message) end, | |
timeout) | |
end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment