Skip to content

Instantly share code, notes, and snippets.

@MikeBild
Last active December 26, 2015 03:29
Show Gist options
  • Save MikeBild/7086032 to your computer and use it in GitHub Desktop.
Save MikeBild/7086032 to your computer and use it in GitHub Desktop.
f.(f) - timeout actor
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