-
-
Save Ayoush/59f8882658923e01e5856378620fcd14 to your computer and use it in GitHub Desktop.
This file contains 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
defmodule OtpConceptsProcesses do | |
def start_link() do | |
spawn_link(__MODULE__, :loop, [%{}]) | |
end | |
def loop(state) do | |
receive do | |
{:add, value} -> | |
new_state = Map.put(state, :add, value) | |
loop(new_state) | |
{:remove, value} -> | |
new_state = Map.put(state, :remove, value) | |
loop(new_state) | |
loop(state) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment