Last active
December 26, 2015 03:29
-
-
Save MikeBild/7086032 to your computer and use it in GitHub Desktop.
f.(f) - timeout actor
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 Actors do | |
def publish do | |
publish(0) | |
end | |
def publish(count) do | |
receive do | |
{:in, pid} -> pid <- {:out, {{:msg, "demo"},{:count, count}}} | |
end | |
publish(count + 1) | |
end | |
end | |
defmodule ActorsTest do | |
def doIt do | |
actor = spawn_link(Actors, :publish, []) | |
actor <- {:in, self()} | |
actor <- {:in, self()} | |
f = fn(f) -> | |
receive do | |
{:out, {{:msg,msg},{:count,count}}} -> IO.puts "#{msg}, #{count}" | |
after | |
1000 -> actor <- {:in, self()} | |
end | |
f.(f) | |
end | |
f.(f) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment