Ensure Registry.match/4 works with :_ as key

This commit is contained in:
José Valim
2017-07-14 01:18:12 +02:00
parent 5f735de4ca
commit 36069cbcde
2 changed files with 6 additions and 1 deletions
+2 -1
View File
@@ -534,7 +534,8 @@ defmodule Registry do
"""
@spec match(registry, key, match_pattern :: atom() | tuple(), guards :: list()) :: [{pid, term}]
def match(registry, key, pattern, guards \\ []) when is_atom(registry) and is_list(guards) do
spec = [{{key, {:_, pattern}}, guards, [{:element, 2, :"$_"}]}]
guards = [{:"=:=", {:element, 1, :"$_"}, {:const, key}} | guards]
spec = [{{:_, {:_, pattern}}, guards, [{:element, 2, :"$_"}]}]
case key_info!(registry) do
{:unique, partitions, key_ets} ->
+4
View File
@@ -69,6 +69,10 @@ defmodule RegistryTest do
[{self(), value}]
assert Registry.match(registry, "hello", {:"$1", :_, :"$1"}) ==
[{self(), value}]
assert Registry.match(registry, "hello", :_) ==
[{self(), value}]
assert Registry.match(registry, :_, :_) ==
[]
end
test "supports guard conditions", %{registry: registry} do