Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/blocking_queue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ defmodule BlockingQueue do
# remove all items using predicate function, handling push waiters
def handle_call({:filter, f}, _, {max, queue, :push, waiters}) when is_list waiters do
filtered_queue = :queue.filter(f, queue)
{still_waiters, filtered_waiters} = Enum.partition waiters, &f.(elem(&1, 1))
{still_waiters, filtered_waiters} = Enum.split_with waiters, &f.(elem(&1, 1))
Enum.each filtered_waiters, &send(elem(elem(&1, 0), 0), :awaken)
{rest, next} = Enum.split still_waiters, :queue.len(filtered_queue) - max
final_queue = Enum.reduce(Enum.reverse(next), filtered_queue, fn({next, item}, q) ->
Expand Down
22 changes: 11 additions & 11 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ defmodule BlockingQueue.Mixfile do
elixir: "~> 1.0",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps,
description: description,
package: package]
deps: deps(),
description: description(),
package: package()]
end

def application do
[applications: [:logger]]
end

defp deps do
defp deps() do
[
{:excheck, "~> 0.2", only: :test},
{:triq, github: "triqng/triq", only: :test},
{:inch_ex, "~> 0.5.4", only: :docs},
{:earmark, "~> 0.1", only: :dev},
{:ex_doc, "~> 0.10", only: :dev}
{:excheck, "~> 0.6", only: :test},
{:triq, "~> 1.3", only: :test},
{:inch_ex, github: "rrrene/inch_ex", only: [:dev, :test]},
{:earmark, "~> 1.3.1", only: :dev},
{:ex_doc, "~> 0.19.2", only: :dev}
]
end

defp description do
defp description() do
"""
BlockingQueue is a simple queue implemented as a GenServer. It has a fixed maximum length established when it is created.
"""
end

defp package do
defp package() do
[files: ["lib", "mix.exs", "README.md", "LICENSE"],
maintainers: ["Joseph Kain"],
licenses: ["MIT"],
Expand Down
19 changes: 13 additions & 6 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
%{"earmark": {:hex, :earmark, "0.1.17", "a2269e72ff85501bdb58c2de9edc0a9a17a4be2757883eed1f601b30494ed2bf", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.10.0", "f49c237250b829df986486b38f043e6f8e19d19b41101987f7214543f75947ec", [:mix], [{:earmark, "~> 0.1.17 or ~> 0.2", [hex: :earmark, optional: true]}]},
"excheck": {:hex, :excheck, "0.2.3", "aa6387c991c76963db542d7d0be6d6b3e14b1932dcb229bb1548093ba8aceae8", [:mix], []},
"inch_ex": {:hex, :inch_ex, "0.5.4", "a2b032ad141a335a0a119f49b157b36326f5928d16a1d129b0f582398fdc25d2", [:mix], [{:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: false]}]},
"poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [:mix], []},
"triq": {:git, "https://github.com/triqng/triq.git", "2c497398e020e06db8496f1d89f12481cc5adab9", []}}
%{
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.19.2", "6f4081ccd9ed081b6dc0bd5af97a41e87f5554de469e7d76025fba535180565f", [:mix], [{:earmark, "~> 1.2", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"excheck": {:hex, :excheck, "0.6.0", "f8595a8ac2c0abc0d060c1a4fce7d26f41574543366a52d5f3c84de30a69747b", [:mix], [], "hexpm"},
"inch_ex": {:git, "https://github.com/rrrene/inch_ex.git", "e44c722afdc20221a35650c31e048d195530f0b0", []},
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"triq": {:hex, :triq, "1.3.0", "d9ed60f3cd2b6bacbb721bc9873e67e07b02e5b97c63d40db35b12670a7f1bf4", [:rebar3], [], "hexpm"},
}
8 changes: 4 additions & 4 deletions test/blocking_queue_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ defmodule BlockingQueueTest do
test "BlockingQueue pop on empty queue can wait beyond GenServer call timeout" do
{:ok, pid} = BlockingQueue.start_link(5)

task = Task.async(fn -> BlockingQueue.pop(pid, 5)end)
task = Task.async(fn -> BlockingQueue.pop(pid, 5) end)
ref = Process.monitor(task.pid)

:timer.sleep 10
Expand All @@ -111,7 +111,7 @@ defmodule BlockingQueueTest do

BlockingQueue.push pid, "Hello"

task = Task.async(fn -> BlockingQueue.push(pid, "World", 5)end)
task = Task.async(fn -> BlockingQueue.push(pid, "World", 5) end)
ref = Process.monitor(task.pid)

:timer.sleep 10
Expand All @@ -120,7 +120,7 @@ defmodule BlockingQueueTest do
end

property "BlockingQueue supports async and blocking pushes and pops" do
for_all xs in list(int) do
for_all xs in list(int()) do
implies length(xs) > 0 do
{:ok, pid} = BlockingQueue.start_link(5)
Task.async(fn ->
Expand All @@ -137,7 +137,7 @@ defmodule BlockingQueueTest do
end

property "BlockingQueue stream API supports blocking pushes and pops" do
for_all xs in list(int) do
for_all xs in list(int()) do
implies length(xs) > 0 do
{:ok, pid} = BlockingQueue.start_link(5)

Expand Down
1 change: 1 addition & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ExCheck.start()
ExUnit.start()