Page MenuHomePhorge

No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/gen_magic/pool.ex b/lib/gen_magic/pool.ex
index fac4cd6..2793f98 100644
--- a/lib/gen_magic/pool.ex
+++ b/lib/gen_magic/pool.ex
@@ -1,55 +1,50 @@
defmodule GenMagic.Pool do
@behaviour NimblePool
def start_link(options, pool_size \\ nil) do
pool_size = pool_size || System.schedulers_online()
NimblePool.start_link(worker: {__MODULE__, options}, pool_size: pool_size)
end
def perform(pool, path, opts \\ []) do
pool_timeout = Keyword.get(opts, :pool_timeout, 5000)
timeout = Keyword.get(opts, :timeout, 5000)
- NimblePool.checkout!(pool, :checkout, fn _from, server ->
- {GenMagic.perform(server, path, timeout), server}
+ 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
- if name, do: Process.register(self(), atom)
+ if name, do: Process.register(self(), name)
{:ok, options}
end
@impl NimblePool
def init_worker(options) do
- {:ok, server} = GenMagic.Server.start_link(options)
- {:ok, server, nil}
+ {:ok, server} = GenMagic.Server.start_link(options || [])
+ {:ok, server, options}
end
@impl NimblePool
- def handle_checkout(:checkout, _, server, state) do
- {:ok, server, server, pool_state}
+ def handle_checkout(:checkout, _from, server) do
+ {:ok, server, server}
end
@impl NimblePool
- def handle_checkin(server, _from, _old_server, state) do
- {:ok, server, state}
+ def handle_checkin(_, _, server) do
+ {:ok, server}
end
@impl NimblePool
def terminate_worker(_reason, _worker, state) do
{:ok, state}
end
- @impl NimblePool
- def terminate(_reason, _conn, state) do
- {:ok, state}
- end
-
end
diff --git a/test/gen_magic/pool_test.exs b/test/gen_magic/pool_test.exs
index f336e12..17c4a9d 100644
--- a/test/gen_magic/pool_test.exs
+++ b/test/gen_magic/pool_test.exs
@@ -1,9 +1,17 @@
defmodule GenMagic.PoollTest do
use GenMagic.MagicCase
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"))
end
end

File Metadata

Mime Type
text/x-diff
Expires
Thu, Nov 28, 5:35 AM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40881
Default Alt Text
(3 KB)

Event Timeline