Merge branch 'nimblepool' into develop
This commit is contained in:
commit
fcab217ea0
2 changed files with 18 additions and 15 deletions
|
@ -10,8 +10,8 @@ defmodule GenMagic.Pool do
|
||||||
pool_timeout = Keyword.get(opts, :pool_timeout, 5000)
|
pool_timeout = Keyword.get(opts, :pool_timeout, 5000)
|
||||||
timeout = Keyword.get(opts, :timeout, 5000)
|
timeout = Keyword.get(opts, :timeout, 5000)
|
||||||
|
|
||||||
NimblePool.checkout!(pool, :checkout, fn _from, server ->
|
NimblePool.checkout!(pool, :checkout, fn _, server ->
|
||||||
{GenMagic.perform(server, path, timeout), server}
|
{GenMagic.Server.perform(server, path, timeout), server}
|
||||||
end, pool_timeout)
|
end, pool_timeout)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,24 +22,24 @@ defmodule GenMagic.Pool do
|
||||||
{nil, options} -> {__MODULE__, options}
|
{nil, options} -> {__MODULE__, options}
|
||||||
{_, options} -> {nil, options}
|
{_, options} -> {nil, options}
|
||||||
end
|
end
|
||||||
if name, do: Process.register(self(), atom)
|
if name, do: Process.register(self(), name)
|
||||||
{:ok, options}
|
{:ok, options}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl NimblePool
|
@impl NimblePool
|
||||||
def init_worker(options) do
|
def init_worker(options) do
|
||||||
{:ok, server} = GenMagic.Server.start_link(options)
|
{:ok, server} = GenMagic.Server.start_link(options || [])
|
||||||
{:ok, server, nil}
|
{:ok, server, options}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl NimblePool
|
@impl NimblePool
|
||||||
def handle_checkout(:checkout, _, server, state) do
|
def handle_checkout(:checkout, _from, server) do
|
||||||
{:ok, server, server, pool_state}
|
{:ok, server, server}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl NimblePool
|
@impl NimblePool
|
||||||
def handle_checkin(server, _from, _old_server, state) do
|
def handle_checkin(_, _, server) do
|
||||||
{:ok, server, state}
|
{:ok, server}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl NimblePool
|
@impl NimblePool
|
||||||
|
@ -47,9 +47,4 @@ defmodule GenMagic.Pool do
|
||||||
{:ok, state}
|
{:ok, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl NimblePool
|
|
||||||
def terminate(_reason, _conn, state) do
|
|
||||||
{:ok, state}
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,15 @@ defmodule GenMagic.PoollTest do
|
||||||
use GenMagic.MagicCase
|
use GenMagic.MagicCase
|
||||||
|
|
||||||
test "pool" do
|
test "pool" do
|
||||||
{:ok, _} = GenMagic.Pool.start_link([name: TestPool])
|
{: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"))
|
||||||
|
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"))
|
||||||
|
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"))
|
assert {:ok, _} = GenMagic.Pool.perform(TestPool, absolute_path("Makefile"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue