Compare commits

..

3 Commits

Author SHA1 Message Date
f2c4e10542 simplified function on paxos
All checks were successful
continuous-integration/drone/push Build is passing
2024-01-09 19:34:26 +00:00
6d929a347f Merge branch 'main' of git.andr3h3nriqu3s.com:andr3/distributed_system_coursework 2024-01-09 19:33:49 +00:00
b8fc3da28c fix: presentaiton
All checks were successful
continuous-integration/drone/push Build is passing
2024-01-09 14:59:48 +00:00

View File

@ -455,25 +455,13 @@ defmodule Paxos do
def propose_loop(inInst) do def propose_loop(inInst) do
receive do receive do
{:timeout, inst} -> {:timeout, inst} ->
if inInst == inst do check_and_apply({:timeout}, inst, inInst, &propose_loop/1)
{:timeout}
else
propose_loop(inInst)
end
{:abort, inst} -> {:abort, inst} ->
if inInst == inst do check_and_apply({:abort}, inst, inInst, &propose_loop/1)
{:abort}
else
propose_loop(inInst)
end
{:decision, inst, d} -> {:decision, inst, d} ->
if inInst == inst do check_and_apply({:decision, d}, inst, inInst, &propose_loop/1)
{:decision, d}
else
propose_loop(inInst)
end
x -> x ->
Process.send_after(self(), x, 500) Process.send_after(self(), x, 500)
@ -489,22 +477,22 @@ defmodule Paxos do
def get_decision_loop(inInst) do def get_decision_loop(inInst) do
receive do receive do
{:get_value_res, inst} -> {:get_value_res, inst} ->
if inst == inInst do check_and_apply(nil, inst, inInst, &get_decision_loop/1)
nil
else
get_decision_loop(inInst)
end
{:get_value_res_actual, inst, v} -> {:get_value_res_actual, inst, v} ->
if inst == inInst do check_and_apply(v, inst, inInst, &get_decision_loop/1)
v
else
get_decision_loop(inInst)
end
x -> x ->
Process.send_after(self(), x, 500) Process.send_after(self(), x, 500)
get_decision_loop(inInst) get_decision_loop(inInst)
end end
end end
def check_and_apply(v, inst, inInst, fun) do
if inst == inInst do
v
else
fun.(inInst)
end
end
end end