Skip to content

Commit

Permalink
Add process added to local Register synchronously (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
studzien authored Oct 28, 2022
1 parent a42e3b9 commit 197bfab
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions lib/horde/registry_impl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,27 @@ defmodule Horde.RegistryImpl do
defp process_diff(state, {:add, {:key, key}, {member, pid, value}}) do
link_local_pid(pid)

case member == fully_qualified_name(state.name) do
true ->
state

false ->
process_add(state, key, member, pid, value)
end
end

defp process_diff(state, {:remove, {:key, key}}) do
unregister_local(state, key)

state
end

defp process_diff(state, {:add, {:registry, key}, value}) do
:ets.insert(state.registry_ets_table, {key, value})
state
end

defp process_add(state, key, member, pid, value) do
add_key_to_pids_table(state, pid, key)

with [{^key, _member, {other_pid, other_value}}] when other_pid != pid <-
Expand All @@ -232,17 +253,6 @@ defmodule Horde.RegistryImpl do
state
end

defp process_diff(state, {:remove, {:key, key}}) do
unregister_local(state, key)

state
end

defp process_diff(state, {:add, {:registry, key}, value}) do
:ets.insert(state.registry_ets_table, {key, value})
state
end

defp add_key_to_pids_table(state, pid, key) do
case :ets.lookup(state.pids_ets_table, pid) do
[] ->
Expand Down Expand Up @@ -305,10 +315,13 @@ defmodule Horde.RegistryImpl do
def handle_call({:register, key, value, pid}, _from, state) do
Process.link(pid)

member = fully_qualified_name(state.name)
state = process_add(state, key, member, pid, value)

DeltaCrdt.put(
crdt_name(state.name),
{:key, key},
{fully_qualified_name(state.name), pid, value},
{member, pid, value},
:infinity
)

Expand Down

0 comments on commit 197bfab

Please sign in to comment.