loop do count = Actor.receive break puts(count) if count > 1000 pong << (count + 1) end end pong = Actor.spawn do loop do count = Actor.receive break puts(count) if count > 1000 ping << (count + 1) end end ping << 1 sleep 1
:ok = :proc_lib.start_link(__MODULE__, :init, [:ping, :pong]) :ok = :proc_lib.start_link(__MODULE__, :init, [:pong, :ping]) :ping <-‐ 1 end def init(my_name, other_name) do Process.register(self(), my_name) :proc_lib.init_ack(:ok) loop(my_name, other_name) end def loop(my_name, other_name) do receive do count -‐> other_name <-‐ (count + 1) if count > 1000 do IO.puts("#{my_name} #{count}") else loop(my_name, other_name) end end end end
loop do count = Actor.receive break puts(count) if count > 1000 pong << (count + 1) end end pong = Actor.spawn do loop do count = Actor.receive break puts(count) if count > 1000 ping << (count + 1) end end ping << 1 sleep 1