Skip to content

Commit

Permalink
feat(Poolboy): ensure Poolboy waits infinitely for a worker
Browse files Browse the repository at this point in the history
To prevent Poolboy from timing out whilst waiting for a worker, the
`:infinity` atom is passed as the `TIMEOUT` argument in the Poolboy
transaction function call. This will ensure Poolboy waits forever for a
worker to become available.

To highlight the issue more, a sleep has been added to the worker to
simulate slow running processes.
  • Loading branch information
Harvey Ball authored and thestonefox committed Nov 24, 2015
1 parent d70cbb7 commit 065b746
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/elixir_poolboy_example.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ defmodule ElixirPoolboyExample do
defp pool_square(x) do
:poolboy.transaction(
pool_name(),
fn(pid) -> :gen_server.call(pid, x) end
fn(pid) -> :gen_server.call(pid, x) end,
:infinity
)
end
end
1 change: 1 addition & 0 deletions lib/elixir_poolboy_example/worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule ElixirPoolboyExample.Worker do
end

def handle_call(data, from, state) do
:timer.sleep(2000)
result = ElixirPoolboyExample.Squarer.square(data)
IO.puts "Worker Reports: #{data} * #{data} = #{result}"
{:reply, [result], state}
Expand Down

0 comments on commit 065b746

Please sign in to comment.