Last active
November 2, 2017 20:57
-
-
Save blackode/dbe29e09b9e480b1c9dfe4f53ddda531 to your computer and use it in GitHub Desktop.
GenServer in Elixir Server Callbacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handle_call({:unlock, password}, _from, passwords) do # ----> synchronous request | |
if password in passwords do | |
{:reply, :ok, passwords} | |
else | |
write_to_logfile password | |
{:reply, {:error,"wrongpassword"}, passwords} | |
end | |
end | |
def handle_call({:reset, {old_password,new_password}}, _from, passwords) do | |
if old_password in passwords do | |
new_state = List.delete(passwords,old_password) | |
{:reply, :ok, [new_password | new_state]} | |
else | |
write_to_logfile new_password | |
{:reply, {:error,"wrongpassword"}, passwords} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment