Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created September 7, 2018 14:34
Show Gist options
  • Save deque-blog/f4be2aacf6ec3a82f129e15ecda6f36a to your computer and use it in GitHub Desktop.
Save deque-blog/f4be2aacf6ec3a82f129e15ecda6f36a to your computer and use it in GitHub Desktop.
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