Skip to content

Instantly share code, notes, and snippets.

@Ayoush
Created August 28, 2020 09:09
Show Gist options
  • Save Ayoush/59f8882658923e01e5856378620fcd14 to your computer and use it in GitHub Desktop.
Save Ayoush/59f8882658923e01e5856378620fcd14 to your computer and use it in GitHub Desktop.
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