Skip to content

Instantly share code, notes, and snippets.

@ryo33
Created August 5, 2017 17:01
Show Gist options
  • Save ryo33/d75ff3441a1ac5e7755feebe888ddde4 to your computer and use it in GitHub Desktop.
Save ryo33/d75ff3441a1ac5e7755feebe888ddde4 to your computer and use it in GitHub Desktop.
Spawn a new process with registering to a registry and receive messages continuously in Elixir
def register_handler(register_func, hander_func) do
spawn_link fn ->
register_func.()
for :ok <- Stream.cycle([:ok]) do
receive do
message -> handler_func.(message)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment