Merge branch 'nimblepool' into develop
This commit is contained in:
commit
6134300c6c
2 changed files with 17 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
|||
defmodule GenMagic.Pool do
|
||||
@behaviour NimblePool
|
||||
@moduledoc "Pool of `GenMagic.Server`"
|
||||
|
||||
def start_link(options, pool_size \\ nil) do
|
||||
pool_size = pool_size || System.schedulers_online()
|
||||
|
@ -10,18 +11,25 @@ defmodule GenMagic.Pool do
|
|||
pool_timeout = Keyword.get(opts, :pool_timeout, 5000)
|
||||
timeout = Keyword.get(opts, :timeout, 5000)
|
||||
|
||||
NimblePool.checkout!(pool, :checkout, fn _, server ->
|
||||
{GenMagic.Server.perform(server, path, timeout), server}
|
||||
end, pool_timeout)
|
||||
NimblePool.checkout!(
|
||||
pool,
|
||||
:checkout,
|
||||
fn _, server ->
|
||||
{GenMagic.Server.perform(server, path, timeout), server}
|
||||
end,
|
||||
pool_timeout
|
||||
)
|
||||
end
|
||||
|
||||
@impl NimblePool
|
||||
def init_pool(options) do
|
||||
{name, options} = case Keyword.pop(options, :name) do
|
||||
{name, options} when is_atom(name) -> {name, options}
|
||||
{nil, options} -> {__MODULE__, options}
|
||||
{_, options} -> {nil, options}
|
||||
end
|
||||
{name, options} =
|
||||
case Keyword.pop(options, :name) do
|
||||
{name, options} when is_atom(name) -> {name, options}
|
||||
{nil, options} -> {__MODULE__, options}
|
||||
{_, options} -> {nil, options}
|
||||
end
|
||||
|
||||
if name, do: Process.register(self(), name)
|
||||
{:ok, options}
|
||||
end
|
||||
|
@ -46,5 +54,4 @@ defmodule GenMagic.Pool do
|
|||
def terminate_worker(_reason, _worker, state) do
|
||||
{:ok, state}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ defmodule GenMagic.PoollTest do
|
|||
use GenMagic.MagicCase
|
||||
|
||||
test "pool" do
|
||||
{:ok, _} = GenMagic.Pool.start_link([name: TestPool, pool_size: 2])
|
||||
{:ok, _} = GenMagic.Pool.start_link(name: TestPool, pool_size: 2)
|
||||
assert {:ok, _} = GenMagic.Pool.perform(TestPool, absolute_path("Makefile"))
|
||||
assert {:ok, _} = GenMagic.Pool.perform(TestPool, absolute_path("Makefile"))
|
||||
assert {:ok, _} = GenMagic.Pool.perform(TestPool, absolute_path("Makefile"))
|
||||
|
@ -13,5 +13,4 @@ defmodule GenMagic.PoollTest do
|
|||
assert {:ok, _} = GenMagic.Pool.perform(TestPool, absolute_path("Makefile"))
|
||||
assert {:ok, _} = GenMagic.Pool.perform(TestPool, absolute_path("Makefile"))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue