Created
August 5, 2017 17:01
-
-
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
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
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