当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Elixir Registry.unregister_match用法及代码示例


Elixir语言中 Registry.unregister_match 相关用法介绍如下。

用法:

unregister_match(registry, key, pattern, guards \\ [])
(从 1.5.0 开始)
@spec unregister_match(registry(), key(), match_pattern(), guards()) :: :ok

取消注册与 registry 中的当前进程关联的模式匹配的键的条目。

例子

对于唯一的注册表,它可以用于根据它是否匹配特定值来有条件地取消注册一个键。

iex> Registry.start_link(keys: :unique, name: Registry.UniqueUnregisterMatchTest)
iex> Registry.register(Registry.UniqueUnregisterMatchTest, "hello", :world)
iex> Registry.keys(Registry.UniqueUnregisterMatchTest, self())
["hello"]
iex> Registry.unregister_match(Registry.UniqueUnregisterMatchTest, "hello", :foo)
:ok
iex> Registry.keys(Registry.UniqueUnregisterMatchTest, self())
["hello"]
iex> Registry.unregister_match(Registry.UniqueUnregisterMatchTest, "hello", :world)
:ok
iex> Registry.keys(Registry.UniqueUnregisterMatchTest, self())
[]

对于重复的注册表:

iex> Registry.start_link(keys: :duplicate, name: Registry.DuplicateUnregisterMatchTest)
iex> Registry.register(Registry.DuplicateUnregisterMatchTest, "hello", :world_a)
iex> Registry.register(Registry.DuplicateUnregisterMatchTest, "hello", :world_b)
iex> Registry.register(Registry.DuplicateUnregisterMatchTest, "hello", :world_c)
iex> Registry.keys(Registry.DuplicateUnregisterMatchTest, self())
["hello", "hello", "hello"]
iex> Registry.unregister_match(Registry.DuplicateUnregisterMatchTest, "hello", :world_a)
:ok
iex> Registry.keys(Registry.DuplicateUnregisterMatchTest, self())
["hello", "hello"]
iex> Registry.lookup(Registry.DuplicateUnregisterMatchTest, "hello")
[{self(), :world_b}, {self(), :world_c}]

相关用法


注:本文由纯净天空筛选整理自elixir-lang.org大神的英文原创作品 Registry.unregister_match(registry, key, pattern, guards \\ [])。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。