Skip to content

Commit

Permalink
Bug fix for lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
surajreddy6 committed Oct 22, 2018
1 parent 50a38e6 commit c75bd1d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/chief.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ defmodule Chief do
def handle_call({:get_succ, node}, _from, state) do
node_list = state[:node_list]
node_i = Enum.find_index(node_list, fn i -> i==node end)
{:reply, Enum.fetch!(node_list, node_i+1), state}
cond do
node_i == nil ->
{:reply, node, state}
node_i == length(node_list) - 1 ->
{:reply, Enum.fetch!(node_list, 0), state}
true ->
{:reply, Enum.fetch!(node_list, node_i+1), state}
end
end
end

0 comments on commit c75bd1d

Please sign in to comment.